annotate lisp/menubar.el @ 2720:6fa9919a9a0b

[xemacs-hg @ 2005-04-08 23:10:01 by crestani] ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         New configure flag: `MC_ALLOC':         * configure.ac (XE_COMPLEX_ARG_ENABLE): Add `--enable-mc-alloc' as         a new configure flag.         * configure.in (AC_INIT_PARSE_ARGS): Add `--mc-alloc' as a new         configure flag.         * configure.usage: Add description for `mc-alloc'.         DUMP_IN_EXEC:         * Makefile.in.in: Condition the installation of a separate dump         file on !DUMP_ON_EXEC.         * configure.ac (XE_COMPLEX_ARG_ENABLE): Add         `--enable-dump-in-exec' as a new configure flag.         * configure.ac: DUMP_IN_EXEC is define as default for PDUMP but         not default for MC_ALLOC.         * configure.in (AC_INIT_PARSE_ARGS): Add `--dump-in-exec' as a         new configure flag.         * configure.in: DUMP_IN_EXEC is define as default for PDUMP but         not default for MC_ALLOC.         * configure.usage: Add description for `dump-in-exec'. lib-src/ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         DUMP_IN_EXEC:                  * Makefile.in.in: Only compile insert-data-in-exec if         DUMP_IN_EXEC is defined. lisp/ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         MEMORY_USAGE_STATS         * diagnose.el: Add new lisp function to pretty print statistics         about the new allocator.         * diagnose.el (show-mc-alloc-memory-usage): New. modules/ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         Remove Lcrecords:                  * postgresql/postgresql.c (allocate_pgconn): Allocate with new         allocator.         * postgresql/postgresql.c (allocate_pgresult): Allocate PGresult         with new allocator.           * postgresql/postgresql.h (struct Lisp_PGconn): Add         lrecord_header.         * postgresql/postgresql.h (struct Lisp_PGresult): Add         lrecord_header.         * ldap/eldap.c (allocate_ldap): Allocate with new allocator.         * ldap/eldap.h (struct Lisp_LDAP): Add lrecord_header. nt/ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         New configure flag: `MC_ALLOC':         * config.inc.samp: Add new flag `MC_ALLOC'.         * xemacs.mak: Add flag and configuration output for `MC_ALLOC'.         New files:         * xemacs.dsp: Add source files mc-alloc.c and mc-alloc.h.         * xemacs.mak: Add new object file mc-alloc.obj to dependencies. src/ChangeLog addition: 2005-04-01  Marcus Crestani  <crestani@xemacs.org>         The new allocator.         New configure flag: `MC_ALLOC':         * config.h.in: Add new flag `MC_ALLOC'.         New files:         * Makefile.in.in: Add new object file mc-alloc.o.         * depend: Add new files to dependencies.         * mc-alloc.c: New.         * mc-alloc.h: New.         Running the new allocator from XEmacs:         * alloc.c (deadbeef_memory): Moved to mc-alloc.c.         * emacs.c (main_1): Initialize the new allocator and add         syms_of_mc_alloc.         * symsinit.h: Add syms_of_mc_alloc.         New lrecord allocation and free functions:         * alloc.c (alloc_lrecord): New. Allocates an lrecord, includes         type checking and initializing of the lrecord_header.         * alloc.c (noseeum_alloc_lrecord): Same as above, but increments         the NOSEEUM cons counter.         * alloc.c (free_lrecord): New. Calls the finalizer and frees the         lrecord.         * lrecord.h: Add lrecord allocation prototypes and comments.         Remove old lrecord FROB block allocation:                  * alloc.c (allocate_lisp_storage): Former function to expand         heap. Not needed anymore, remove.         * alloc.c: Completely remove `Fixed-size type macros'         * alloc.c (release_breathing_space): Remove.         * alloc.c (memory_full): Remove release_breathing_space.         * alloc.c (refill_memory_reserve): Remove.         * alloc.c (TYPE_ALLOC_SIZE): Remove.         * alloc.c (DECLARE_FIXED_TYPE_ALLOC): Remove.         * alloc.c (ALLOCATE_FIXED_TYPE_FROM_BLOCK): Remove.         * alloc.c (ALLOCATE_FIXED_TYPE_1): Remove.         * alloc.c (ALLOCATE_FIXED_TYPE): Remove.         * alloc.c (NOSEEUM_ALLOCATE_FIXED_TYPE): Remove.         * alloc.c (struct Lisp_Free): Remove.         * alloc.c (LRECORD_FREE_P): Remove.         * alloc.c (MARK_LRECORD_AS_FREE): Remove.         * alloc.c (MARK_LRECORD_AS_NOT_FREE): Remove.         * alloc.c (PUT_FIXED_TYPE_ON_FREE_LIST): Remove.         * alloc.c (FREE_FIXED_TYPE): Remove.         * alloc.c (FREE_FIXED_TYPE_WHEN_NOT_IN_GC): Remove.         Allocate old lrecords with new allocator:                  * alloc.c: DECLARE_FIXED_TYPE_ALLOC removed for all lrecords         defined in alloc.c.         * alloc.c (Fcons): Allocate with new allocator.         * alloc.c (noseeum_cons): Allocate with new allocator.         * alloc.c (make_float): Allocate with new allocator.         * alloc.c (make_bignum): Allocate with new allocator.         * alloc.c (make_bignum_bg): Allocate with new allocator.         * alloc.c (make_ratio): Allocate with new allocator.         * alloc.c (make_ratio_bg): Allocate with new allocator.         * alloc.c (make_ratio_rt): Allocate with new allocator.         * alloc.c (make_bigfloat): Allocate with new allocator.         * alloc.c (make_bigfloat_bf): Allocate with new allocator.         * alloc.c (make_compiled_function): Allocate with new allocator.         * alloc.c (Fmake_symbol): Allocate with new allocator.         * alloc.c (allocate_extent): Allocate with new allocator.         * alloc.c (allocate_event): Allocate with new allocator.         * alloc.c (make_key_data): Allocate with new allocator.         * alloc.c (make_button_data): Allocate with new allocator.         * alloc.c (make_motion_data): Allocate with new allocator.         * alloc.c (make_process_data): Allocate with new allocator.         * alloc.c (make_timeout_data): Allocate with new allocator.         * alloc.c (make_magic_data): Allocate with new allocator.         * alloc.c (make_magic_eval_data): Allocate with new allocator.         * alloc.c (make_eval_data): Allocate with new allocator.         * alloc.c (make_misc_user_data): Allocate with new allocator.         * alloc.c (Fmake_marker): Allocate with new allocator.         * alloc.c (noseeum_make_marker): Allocate with new allocator.         * alloc.c (make_uninit_string): Allocate with new allocator.         * alloc.c (resize_string): Allocate with new allocator.         * alloc.c (make_string_nocopy): Allocate with new allocator.         Garbage Collection:         * alloc.c (GC_CHECK_NOT_FREE): Remove obsolete assertions.         * alloc.c (SWEEP_FIXED_TYPE_BLOCK): Remove.         * alloc.c (SWEEP_FIXED_TYPE_BLOCK_1): Remove.         * alloc.c (sweep_conses): Remove.         * alloc.c (free_cons): Use new allocator to free.         * alloc.c (sweep_compiled_functions): Remove.         * alloc.c (sweep_floats): Remove.         * alloc.c (sweep_bignums): Remove.         * alloc.c (sweep_ratios): Remove.         * alloc.c (sweep_bigfloats): Remove.         * alloc.c (sweep_symbols): Remove.         * alloc.c (sweep_extents): Remove.         * alloc.c (sweep_events): Remove.         * alloc.c (sweep_key_data): Remove.         * alloc.c (free_key_data): Use new allocator to free.         * alloc.c (sweep_button_data): Remove.         * alloc.c (free_button_data): Use new allocator to free.         * alloc.c (sweep_motion_data): Remove.         * alloc.c (free_motion_data): Use new allocator to free.         * alloc.c (sweep_process_data): Remove.         * alloc.c (free_process_data): Use new allocator to free.         * alloc.c (sweep_timeout_data): Remove.         * alloc.c (free_timeout_data): Use new allocator to free.         * alloc.c (sweep_magic_data): Remove.         * alloc.c (free_magic_data): Use new allocator to free.         * alloc.c (sweep_magic_eval_data): Remove.         * alloc.c (free_magic_eval_data): Use new allocator to free.         * alloc.c (sweep_eval_data): Remove.         * alloc.c (free_eval_data): Use new allocator to free.         * alloc.c (sweep_misc_user_data): Remove.         * alloc.c (free_misc_user_data): Use new allocator to free.         * alloc.c (sweep_markers): Remove.         * alloc.c (free_marker): Use new allocator to free.         * alloc.c (garbage_collect_1): Remove release_breathing_space.         * alloc.c (gc_sweep): Remove all the old lcrecord and lrecord         related stuff. Sweeping now works like this: compact string         chars, finalize, sweep.         * alloc.c (common_init_alloc_early): Remove old lrecord         initializations, remove breathing_space.         * emacs.c (Fdump_emacs): Remove release_breathing_space.         * lisp.h: Remove prototype for release_breathing_space.         * lisp.h: Adjust the special cons mark makros.         Lrecord Finalizer:         * alloc.c: Add finalizer to lrecord definition.         * alloc.c (finalize_string): Add finalizer for string.         * bytecode.c: Add finalizer to lrecord definition.         * bytecode.c (finalize_compiled_function): Add finalizer for         compiled function.         * marker.c: Add finalizer to lrecord definition.         * marker.c (finalize_marker): Add finalizer for marker.         These changes build the interface to mc-alloc:         * lrecord.h (MC_ALLOC_CALL_FINALIZER): Tell mc-alloc how to         finalize lrecords.         * lrecord.h (MC_ALLOC_CALL_FINALIZER_FOR_DISKSAVE): Tell         mc-alloc how to finalize for disksave.         Unify lrecords and lcrecords:         * lisp.h (struct Lisp_String): Adjust string union hack to         new lrecord header.         * lrecord.h: Adjust comments.         * lrecord.h (struct lrecord_header): The new lrecord header         includes type, lisp-readonly, free, and uid.         * lrecord.h (set_lheader_implementation): Adjust to new         lrecord_header.         * lrecord.h (struct lrecord_implementation): The field basic_p         for indication of an old lrecord is not needed anymore, remove.         * lrecord.h (MAKE_LRECORD_IMPLEMENTATION): Remove basic_p.         * lrecord.h (MAKE_EXTERNAL_LRECORD_IMPLEMENTATION): Remove         basic_p.         * lrecord.h (copy_sized_lrecord): Remove distinction between         old lrecords and lcrecords.         * lrecord.h (copy_lrecord): Remove distinction between old         lrecords and lcrecords.         * lrecord.h (zero_sized_lrecord): Remove distinction between         old lrecords and lcrecords.         * lrecord.h (zero_lrecord): Remove distinction between old         lrecords and lcrecords.         Remove lcrecords and lcrecord lists:         * alloc.c (basic_alloc_lcrecord): Not needed anymore, remove.         * alloc.c (very_old_free_lcrecord): Not needed anymore, remove.         * alloc.c (copy_lisp_object): No more distinction between         lrecords and lcrecords.         * alloc.c (all_lcrecords): Not needed anymore, remove.         * alloc.c (make_vector_internal): Allocate as lrecord.         * alloc.c (make_bit_vector_internal): Allocate as lrecord.         * alloc.c: Completely remove `lcrecord lists'.         * alloc.c (free_description): Remove.         * alloc.c (lcrecord_list_description): Remove.         * alloc.c (mark_lcrecord_list): Remove.         * alloc.c (make_lcrecord_list): Remove.         * alloc.c (alloc_managed_lcrecord): Remove.         * alloc.c (free_managed_lcrecord): Remove.         * alloc.c (alloc_automanaged_lcrecord): Remove.         * alloc.c (free_lcrecord): Remove.         * alloc.c (lcrecord_stats): Remove.         * alloc.c (tick_lcrecord_stats): Remove.         * alloc.c (disksave_object_finalization_1): Add call to         mc_finalize_for_disksave. Remove the lcrecord way to visit all         objects.         * alloc.c (kkcc_marking): Remove XD_FLAG_FREE_LISP_OBJECT         * alloc.c (sweep_lcrecords_1): Remove.         * alloc.c (common_init_alloc_early): Remove everything related         to lcrecords, remove old lrecord initializations,         * alloc.c (init_lcrecord_lists): Not needed anymore, remove.         * alloc.c (reinit_alloc_early): Remove everything related to         lcrecords.         * alloc.c (init_alloc_once_early): Remove everything related to         lcrecords.         * buffer.c (allocate_buffer): Allocate as lrecord.         * buffer.c (nuke_all_buffer_slots): Use lrecord functions.         * buffer.c (common_init_complex_vars_of_buffer): Allocate as         lrecord.         * buffer.h (struct buffer): Add lrecord_header.         * casetab.c (allocate_case_table): Allocate as lrecord.         * casetab.h (struct Lisp_Case_Table): Add lrecord_header.         * charset.h (struct Lisp_Charset): Add lrecord_header.         * chartab.c (fill_char_table): Use lrecord functions.         * chartab.c (Fmake_char_table): Allocate as lrecord.         * chartab.c (make_char_table_entry): Allocate as lrecord.         * chartab.c (copy_char_table_entry): Allocate as lrecord.         * chartab.c (Fcopy_char_table): Allocate as lrecord.         * chartab.c (put_char_table): Use lrecord functions.         * chartab.h (struct Lisp_Char_Table_Entry): Add lrecord_header.         * chartab.h (struct Lisp_Char_Table): Add lrecord_header.         * console-impl.h (struct console): Add lrecord_header.         * console-msw-impl.h (struct Lisp_Devmode): Add lrecord_header.         * console-msw-impl.h (struct mswindows_dialog_id): Add         lrecord_header.         * console.c (allocate_console): Allocate as lrecord.         * console.c (nuke_all_console_slots): Use lrecord functions.         * console.c (common_init_complex_vars_of_console): Allocate as         lrecord.         * data.c (make_weak_list): Allocate as lrecord.         * data.c (make_weak_box): Allocate as lrecord.         * data.c (make_ephemeron): Allocate as lrecord.         * database.c (struct Lisp_Database): Add lrecord_header.         * database.c (allocate_database): Allocate as lrecord.         * device-impl.h (struct device): Add lrecord_header.         * device-msw.c (allocate_devmode): Allocate as lrecord.         * device.c (nuke_all_device_slots): Use lrecord functions.         * device.c (allocate_device): Allocate as lrecord.         * dialog-msw.c (handle_question_dialog_box): Allocate as lrecord.         * elhash.c (struct Lisp_Hash_Table): Add lrecord_header.         * elhash.c (make_general_lisp_hash_table): Allocate as lrecord.         * elhash.c (Fcopy_hash_table): Allocate as lrecord.         * event-stream.c: Lcrecord lists Vcommand_builder_free_list and         Vtimeout_free_list are no longer needed. Remove.         * event-stream.c (allocate_command_builder): Allocate as lrecord.         * event-stream.c (free_command_builder): Use lrecord functions.         * event-stream.c (event_stream_generate_wakeup): Allocate as         lrecord.         * event-stream.c (event_stream_resignal_wakeup): Use lrecord         functions.         * event-stream.c (event_stream_disable_wakeup): Use lrecord         functions.         * event-stream.c (reinit_vars_of_event_stream): Lcrecord lists         remove.         * events.h (struct Lisp_Timeout): Add lrecord_header.         * events.h (struct command_builder): Add lrecord_header.         * extents-impl.h (struct extent_auxiliary): Add lrecord_header.         * extents-impl.h (struct extent_info): Add lrecord_header.         * extents.c (allocate_extent_auxiliary): Allocate as lrecord.         * extents.c (allocate_extent_info): Allocate as lrecord.         * extents.c (copy_extent): Allocate as lrecord.         * faces.c (allocate_face): Allocate as lrecord.         * faces.h (struct Lisp_Face): Add lrecord_header.         * file-coding.c (allocate_coding_system): Allocate as lrecord.         * file-coding.c (Fcopy_coding_system): Allocate as lrecord.         * file-coding.h (struct Lisp_Coding_System): Add lrecord_header.         * fns.c (Ffillarray): Allocate as lrecord.         * frame-impl.h (struct frame): Add lrecord_header.         * frame.c (nuke_all_frame_slots): Use lrecord functions.         * frame.c (allocate_frame_core): Allocate as lrecord.         * glyphs.c (allocate_image_instance): Allocate as lrecord.         * glyphs.c (Fcolorize_image_instance): Allocate as lrecord.         * glyphs.c (allocate_glyph): Allocate as lrecord.         * glyphs.h (struct Lisp_Image_Instance): Add lrecord_header.         * glyphs.h (struct Lisp_Glyph): Add lrecord_header.         * gui.c (allocate_gui_item): Allocate as lrecord.         * gui.h (struct Lisp_Gui_Item): Add lrecord_header.         * keymap.c (struct Lisp_Keymap): Add lrecord_header.         * keymap.c (make_keymap): Allocate as lrecord.         * lisp.h (struct Lisp_Vector): Add lrecord_header.         * lisp.h (struct Lisp_Bit_Vector): Add lrecord_header.         * lisp.h (struct weak_box): Add lrecord_header.         * lisp.h (struct ephemeron): Add lrecord_header.         * lisp.h (struct weak_list): Add lrecord_header.         * lrecord.h (struct lcrecord_header): Not used, remove.         * lrecord.h (struct free_lcrecord_header): Not used, remove.         * lrecord.h (struct lcrecord_list): Not needed anymore, remove.         * lrecord.h (lcrecord_list): Not needed anymore, remove.         * lrecord.h: (enum data_description_entry_flags): Remove         XD_FLAG_FREE_LISP_OBJECT.         * lstream.c: Lrecord list Vlstream_free_list remove.         * lstream.c (Lstream_new): Allocate as lrecord.         * lstream.c (Lstream_delete): Use lrecod functions.         * lstream.c (reinit_vars_of_lstream): Vlstream_free_list         initialization remove.           * lstream.h (struct lstream): Add lrecord_header.         * emacs.c (main_1): Remove lstream initialization.         * mule-charset.c (make_charset): Allocate as lrecord.         * objects-impl.h (struct Lisp_Color_Instance): Add         lrecord_header.         * objects-impl.h (struct Lisp_Font_Instance): Add lrecord_header.         * objects.c (Fmake_color_instance): Allocate as lrecord.         * objects.c (Fmake_font_instance): Allocate as lrecord.         * objects.c (reinit_vars_of_objects): Allocate as lrecord.         * opaque.c: Lcreord list Vopaque_ptr_list remove.         * opaque.c (make_opaque): Allocate as lrecord.         * opaque.c (make_opaque_ptr): Allocate as lrecord.         * opaque.c (free_opaque_ptr): Use lrecord functions.         * opaque.c (reinit_opaque_early):         * opaque.c (init_opaque_once_early): Vopaque_ptr_list         initialization remove.         * opaque.h (Lisp_Opaque): Add lrecord_header.         * opaque.h (Lisp_Opaque_Ptr): Add lrecord_header.         * emacs.c (main_1): Remove opaque variable initialization.         * print.c (default_object_printer): Use new lrecord_header.         * print.c (print_internal): Use new lrecord_header.         * print.c (debug_p4): Use new lrecord_header.         * process.c (make_process_internal): Allocate as lrecord.         * procimpl.h (struct Lisp_Process): Add lrecord_header.         * rangetab.c (Fmake_range_table): Allocate as lrecord.         * rangetab.c (Fcopy_range_table): Allocate as lrecord.         * rangetab.h (struct Lisp_Range_Table): Add lrecord_header.         * scrollbar.c (create_scrollbar_instance): Allocate as lrecord.         * scrollbar.h (struct scrollbar_instance): Add lrecord_header.         * specifier.c (make_specifier_internal): Allocate as lrecord.         * specifier.h (struct Lisp_Specifier): Add lrecord_header.         * symbols.c:         * symbols.c (Fmake_variable_buffer_local): Allocate as lrecord.         * symbols.c (Fdontusethis_set_symbol_value_handler): Allocate         as lrecord.         * symbols.c (Fdefvaralias): Allocate as lrecord.         * symeval.h (struct symbol_value_magic): Add lrecord_header.         * toolbar.c (update_toolbar_button): Allocate as lrecord.         * toolbar.h (struct toolbar_button): Add lrecord_header.         * tooltalk.c (struct Lisp_Tooltalk_Message): Add lrecord_header.         * tooltalk.c (make_tooltalk_message): Allocate as lrecord.         * tooltalk.c (struct Lisp_Tooltalk_Pattern): Add lrecord_header.         * tooltalk.c (make_tooltalk_pattern): Allocate as lrecord.         * ui-gtk.c (allocate_ffi_data): Allocate as lrecord.         * ui-gtk.c (allocate_emacs_gtk_object_data): Allocate as lrecord.         * ui-gtk.c (allocate_emacs_gtk_boxed_data): Allocate as lrecord.         * ui-gtk.h (structs): Add lrecord_header.         * window-impl.h (struct window): Add lrecord_header.         * window-impl.h (struct window_mirror): Add lrecord_header.         * window.c (allocate_window): Allocate as lrecord.         * window.c (new_window_mirror): Allocate as lrecord.         * window.c (make_dummy_parent): Allocate as lrecord.         MEMORY_USAGE_STATS         * alloc.c (fixed_type_block_overhead): Not used anymore, remove.         * buffer.c (compute_buffer_usage): Get storage size from new         allocator.         * marker.c (compute_buffer_marker_usage): Get storage size from         new allocator.         * mule-charset.c (compute_charset_usage): Get storage size from         new allocator.         * scrollbar-gtk.c (gtk_compute_scrollbar_instance_usage): Get         storage size from new allocator.         * scrollbar-msw.c (mswindows_compute_scrollbar_instance_usage):         Get storage size from new allocator.         * scrollbar-x.c (x_compute_scrollbar_instance_usage): Get         storage size from new allocator.         * scrollbar.c (compute_scrollbar_instance_usage): Get storage         size from new allocator.         * unicode.c (compute_from_unicode_table_size_1): Get storage         size from new allocator.         * unicode.c (compute_to_unicode_table_size_1): Get storage size         from new allocator.         * window.c (compute_window_mirror_usage): Get storage size from         new allocator.         * window.c (compute_window_usage): Get storage size from new         allocator.         MC_ALLOC_TYPE_STATS:         * alloc.c (alloc_lrecord): Bump lrecord count.         * alloc.c (noseeum_alloc_lrecord): Bump lrecord count.         * alloc.c (struct lrecord_stats): Storage for counts.         * alloc.c (init_lrecord_stats): Zero statistics.         * alloc.c (inc_lrecord_stats): Increase the statistic.         * alloc.c (dec_lrecord_stats): Decrease the statistic.         * alloc.c (gc_plist_hack): Used to print the information.         * alloc.c (Fgarbage_collect): Return the collected information.         * mc-alloc.c (remove_cell): Decrease lrecord count.         * mc-alloc.h: Set flag MC_ALLOC_TYPE_STATS.         * emacs.c (main_1): Init lrecord statistics.         * lrecord.h: Add prototypes for *_lrecord_stats.         Strings:         * alloc.c (Fmake_string): Initialize ascii_begin to zero.         * alloc.c (gc_count_num_short_string_in_use): Remove.         * alloc.c (gc_count_string_total_size): Remove.         * alloc.c (gc_count_short_string_total_size): Remove.         * alloc.c (debug_string_purity): Remove.         * alloc.c (debug_string_purity_print): Remove.         * alloc.c (sweep_strings): Remove.                  Remove static C-readonly Lisp objects:         * alloc.c (c_readonly): Not needed anymore, remove.         * alloc.c (GC_CHECK_LHEADER_INVARIANTS): Remove some obsolete         lheader invariants assertions.         * buffer.c (DEFVAR_BUFFER_LOCAL_1): Allocate dynamically.         * console.c (DEFVAR_CONSOLE_LOCAL_1): Allocate dynamically.         * gpmevent.c: Indirection via MC_ALLOC_Freceive_gpm_event.         * gpmevent.c (Fgpm_enable): Allocate dynamically.         * gpmevent.c (syms_of_gpmevent): Allocate dynamically.         * lisp.h (C_READONLY): Not needed anymore, remove.         * lisp.h (DEFUN): Allocate dynamically.         * lrecord.h (C_READONLY_RECORD_HEADER_P): Not needed anymore,         remove.         * lrecord.h (SET_C_READONLY_RECORD_HEADER): Not needed anymore,         remove.         * symbols.c (guts_of_unbound_marker):         * symeval.h (defsubr): Allocate dynamically.         * symeval.h (DEFSUBR_MACRO): Allocate dynamically.         * symeval.h (DEFVAR_ SYMVAL_FWD): Allocate dynamically.         * tests.c (TESTS_DEFSUBR): Allocate dynamically.         Definition of mcpro:         * lisp.h: Add mcpro prototypes.         * alloc.c (common_init_alloc_early): Add initialization for         mcpros.         * alloc.c (mcpro_description_1): New.         * alloc.c (mcpro_description): New.         * alloc.c (mcpros_description_1): New.         * alloc.c (mcpros_description): New.         * alloc.c (mcpro_one_name_description_1): New.         * alloc.c (mcpro_one_name_description): New.         * alloc.c (mcpro_names_description_1): New.         * alloc.c (mcpro_names_description): New.         * alloc.c (mcpros): New.         * alloc.c (mcpro_names): New.         * alloc.c (mcpro_1): New.         * alloc.c (mc_pro): New.         * alloc.c (garbage_collect_1): Add mcpros to root set.         Usage of mcpro:         * alloc.c (make_string_nocopy): Add string to root set.         * symbols.c (init_symbols_once_early): Add Qunbound to root set.         Changes to the Portable Dumper:                  * alloc.c (FREE_OR_REALLOC_BEGIN): Since dumped objects can be         freed with the new allocator, remove assertion for !DUMPEDP.         * dumper.c: Adjust comments, increase PDUMP_HASHSIZE.         * dumper.c (pdump_make_hash): Shift address only 2 bytes, to         avoid collisions.         * dumper.c (pdump_objects_unmark): No more mark bits within         the object, remove.         * dumper.c (mc_addr_elt): New. Element data structure for mc         hash table.         * dumper.c (pdump_mc_hash): New hash table: `lookup table'.         * dumper.c (pdump_get_mc_addr): New. Lookup for hash table.         * dumper.c (pdump_get_indirect_mc_addr): New. Lookup for         convertibles.         * dumper.c (pdump_put_mc_addr): New. Putter for hash table.         * dumper.c (pdump_dump_mc_data): New. Writes the table for         relocation at load time to the dump file.         * dumper.c (pdump_scan_lisp_objects_by_alignment): New.         Visits all dumped Lisp objects.         * dumper.c (pdump_scan_non_lisp_objects_by_alignment): New.         Visits all other dumped objects.         * dumper.c (pdump_reloc_one_mc): New. Updates all pointers         of an object by using the hash table pdump_mc_hash.         * dumper.c (pdump_reloc_one): Replaced by pdump_reloc_one_mc.         * dumper.c (pdump): Change the structure of the dump file, add         the mc post dump relocation table to dump file.         * dumper.c (pdump_load_finish): Hand all dumped objects to the         new allocator and use the mc post dump relocation table for         relocating the dumped objects at dump file load time, free not         longer used data structures.         * dumper.c (pdump_load): Free the dump file.         * dumper.h: Remove pdump_objects_unmark.         * lrecord.h (DUMPEDP): Dumped objects can be freed, remove.              DUMP_IN_EXEC:         * Makefile.in.in: Linking for and with dump in executable only if         DUMP_IN_EXEC is defined.         * config.h.in: Add new flag `DUMP_IN_EXEC'         * emacs.c: Condition dump-data.h on DUMP_IN_EXEC.         * emacs.c (main_1): Flag `-si' only works if dump image is         written into executable.         Miscellanious         * lrecord.h (enum lrecord_type): Added numbers to all types,         very handy for debugging.         * xemacs.def.in.in: Add mc-alloc functions to make them visible         to the modules.
author crestani
date Fri, 08 Apr 2005 23:11:35 +0000
parents 979c4c930bb5
children 79c5457563f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; menubar.el --- Menubar support for XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1991-4, 1997-1998 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
2545
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
5 ;; Copyright (C) 1995, 1996, 2003 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; Keywords: internal, extensions, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
23 ;; along with XEmacs; see the file COPYING. If not, write to the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;;; Synched up with: Not in FSF. (Completely divergent from FSF menu-bar.el)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;; This file is dumped with XEmacs (when menubar support is compiled in).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
33 ;; Some stuff in FSF menu-bar.el is in menubar-items.el
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 (defgroup menu nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 "Input from the menus."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 :group 'environment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 (defvar default-menubar nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;; this function is considered "part of the lexicon" by many,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;; so we'll leave it here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 (defun kill-this-buffer () ; for the menubar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 "Kill the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 (kill-buffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 (defun set-menubar-dirty-flag ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 "Tell XEmacs that the menubar has to be updated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 NOTE: XEmacs now recognizes when you set a different value for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 `current-menubar'. You *only* need to call this function if you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 destructively modify a part of the menubar and don't set `current-menubar'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 Note that all the functions that modify a menu call this automatically."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 (setq-default current-menubar (default-value 'current-menubar)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 ;; #### shouldn't this perhaps be `copy-tree'?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 (defun set-menubar (menubar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 "Set the default menubar to be MENUBAR.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 See `current-menubar' for a description of the syntax of a menubar."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 (check-menu-syntax menubar t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 (setq-default current-menubar (copy-sequence menubar)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (defun set-buffer-menubar (menubar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 "Set the buffer-local menubar to be MENUBAR.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 See `current-menubar' for a description of the syntax of a menubar."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 (check-menu-syntax menubar t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (make-local-variable 'current-menubar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (setq current-menubar (copy-sequence menubar)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 (defun check-menu-syntax (menu &optional menubar-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 ;; The C code does syntax checking on the value of `current-menubar',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 ;; but it's better to do it early, before things have gotten messed up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 (if menubar-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 (or (stringp (car menu))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (signal 'error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 (list "menu name (first element) must be a string" menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 ;;(or (cdr menu) (signal 'error (list "menu is empty" menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 (setq menu (cdr menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 (let (menuitem item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 (while (keywordp (setq item (car menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 (or (memq item '(:config :included :filter :accelerator))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 (signal 'error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 (list "menu keyword must be :config, :included, :accelerator or :filter"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 item)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (if (or (not (cdr menu))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 (vectorp (nth 1 menu))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 (keywordp (nth 1 menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 (signal 'error (list "strange keyword value" item (nth 1 menu))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 (setq menu (nthcdr 2 menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (while menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (setq menuitem (car menu))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 ((stringp menuitem)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 (and (string-match "^\\(-+\\|=+\\):\\(.*\\)" menuitem)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 (setq item (match-string 2 menuitem))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
99 (or (member item '(;; Motif-compatible
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 "singleLine"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 "doubleLine"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 "singleDashedLine"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 "doubleDashedLine"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 "noLine"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 "shadowEtchedIn"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 "shadowEtchedOut"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 "shadowEtchedInDash"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 "shadowEtchedOutDash"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 ;; non-Motif (Lucid menubar widget only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 "shadowDoubleEtchedIn"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 "shadowDoubleEtchedOut"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 "shadowDoubleEtchedInDash"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 "shadowDoubleEtchedOutDash"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 (signal 'error (list "bogus separator style in menu item" item)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ((null menuitem)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 (or menubar-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 (signal 'error (list "nil is only permitted in the top level of menubars"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ((consp menuitem)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 (check-menu-syntax menuitem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 ((vectorp menuitem)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 (let ((L (length menuitem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 plistp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (and (< L 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 (signal 'error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 (list "button descriptors must be at least 2 long"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 menuitem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 (setq plistp (or (>= L 5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 (and (> L 2) (keywordp (aref menuitem 2)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 (if plistp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 (let ((i 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 selp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 (while (< i L)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 (setq item (aref menuitem i))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 (cond ((not (memq item '(:active :suffix :keys :style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 :full :included :selected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 :accelerator)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 (signal 'error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 (list (if (keywordp item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 "unknown menu item keyword"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 "not a keyword")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 item menuitem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 ((eq item :style)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 (setq style (aref menuitem (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (or (memq style '(nil toggle radio button text))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 (signal 'error (list "unknown style" style
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 menuitem))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 ((eq item :selected) (setq selp t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 (setq i (+ i (if (eq item :full) 1 2))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (if (and selp (not (memq style '(toggle button radio))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 (signal 'error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 ":selected only makes sense with :style toggle, radio, or button"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 menuitem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 ;; (t (signal 'error (list "unrecognized menu descriptor" menuitem))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (t (message "unrecognized menu descriptor %s" (prin1-to-string menuitem))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (setq menu (cdr menu)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
2545
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
166 ;;; basic menu manipulation functions
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
2545
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
168 (defun menu-item-text (item &optional normalize)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
169 "Return the text that is displayed for a menu item.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
170 If ITEM is a string (unselectable text), it is returned; otherwise,
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
171 the first element of the cons or vector is returned.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
172 If NORMALIZE is non-nil, pass the text through `normalize-menu-text'
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
173 before being returned, to remove accelerator specs and convert %% to %."
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
174 (let ((val (if (stringp item) item (elt item 0))))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
175 (if normalize (normalize-menu-text val) val)))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
176
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
177 (defun find-menu-item (menubar item-path-list)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
178 "Search MENUBAR for item given by ITEM-PATH-LIST.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 Returns (ITEM . PARENT), where PARENT is the immediate parent of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 the item found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 If the item does not exist, the car of the returned value is nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 If some menu in the ITEM-PATH-LIST does not exist, an error is signalled."
2545
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
183 (find-menu-item-1 menubar item-path-list))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
184
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
185 (defun find-menu-item-1 (menubar item-path-list &optional parent)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (check-argument-type 'listp item-path-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (if (not (consp menubar))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 (let ((rest menubar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 result)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (when (stringp (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 (setq rest (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 (while (keywordp (car rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 (setq rest (cddr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 (if (and (car rest)
2545
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
197 (stringp (car item-path-list))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
198 (= 0 (compare-menu-text (car item-path-list)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
199 (menu-item-text (car rest)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (setq result (car rest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 rest nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (setq rest (cdr rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (if (cdr item-path-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (cond ((consp result)
2571
979c4c930bb5 [xemacs-hg @ 2005-02-07 19:30:07 by ben]
ben
parents: 2545
diff changeset
205 (find-menu-item-1 (cdr result) (cdr item-path-list) result))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (result
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (signal 'error (list (gettext "not a submenu") result)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (signal 'error (list (gettext "no such submenu")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 (car item-path-list)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (cons result parent)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (defun add-menu-item-1 (leaf-p menu-path new-item before in-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 ;; This code looks like it could be cleaned up some more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 ;; Do we really need 6 calls to find-menu-item?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (let* ((item-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (cond ((vectorp new-item) (aref new-item 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 ((consp new-item) (car new-item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 (t nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (menubar (or in-menu current-menubar))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (menu (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (car (find-menu-item menubar menu-path))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (error nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (item-found (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 ((null item-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 ((not (listp menu))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (signal 'error (list (gettext "not a submenu")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 menu-path)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 (find-menu-item (cdr menu) (list item-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (find-menu-item menubar (list item-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (unless menubar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (error "`current-menubar' is nil: can't add menus to it."))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (unless menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (let ((rest menu-path)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (so-far menubar))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 ;;; (setq menu (car (find-menu-item (cdr so-far) (list (car rest)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (setq menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (if (eq so-far menubar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (car (find-menu-item so-far (list (car rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (car (find-menu-item (cdr so-far) (list (car rest))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (unless menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (let ((rest2 so-far))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (while (and (cdr rest2) (car (cdr rest2)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (setq rest2 (cdr rest2)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (setcdr rest2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (nconc (list (setq menu (list (car rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (cdr rest2)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 (setq so-far menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (setq rest (cdr rest)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (if (and item-found (car item-found))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 ;; hack the item in place.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 (if menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 ;; Isn't it very bad form to use nsubstitute for side effects?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (nsubstitute new-item (car item-found) menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (setq current-menubar (nsubstitute new-item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (car item-found)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 current-menubar)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 ;; OK, we have to add the whole thing...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 ;; if BEFORE is specified, try to add it there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (unless menu (setq menu current-menubar))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (when before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (setq before (car (find-menu-item menu (list before)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (let ((rest menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (added-before nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (while rest
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (if (eq before (car (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (setcdr rest (cons new-item (cdr rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (setq rest nil added-before t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (setq rest (cdr rest))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (when (not added-before)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 ;; adding before the first item on the menubar itself is harder
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (if (and (eq menu menubar) (eq before (car menu)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (setq menu (cons new-item menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 current-menubar menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 ;; otherwise, add the item to the end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (nconc menu (list new-item))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (set-menubar-dirty-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 new-item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (defun add-menu-button (menu-path menu-leaf &optional before in-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 "Add a menu item to some menu, creating the menu first if necessary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 If the named item exists already, it is changed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 MENU-PATH identifies the menu under which the new menu item should be inserted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 It is a list of strings; for example, (\"File\") names the top-level \"File\"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 MENU-LEAF is a menubar leaf node. See the documentation of `current-menubar'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 BEFORE, if provided, is the name of a menu item before which this item should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 be added, if this item is not on the menu already. If the item is already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 present, it will not be moved.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
296 IN-MENU, if provided, means use that instead of `current-menubar' as the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
297 menu to change."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 ;; Note easymenu.el uses the fact that menu-leaf can be a submenu.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (add-menu-item-1 t menu-path menu-leaf before in-menu))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 ;; I actually liked the old name better, but the interface has changed too
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
302 ;; drastically to keep it. --Stig
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (defun add-submenu (menu-path submenu &optional before in-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 "Add a menu to the menubar or one of its submenus.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 If the named menu exists already, it is changed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 MENU-PATH identifies the menu under which the new menu should be inserted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 It is a list of strings; for example, (\"File\") names the top-level \"File\"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 menu. (\"File\" \"Foo\") names a hypothetical submenu of \"File\".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 If MENU-PATH is nil, then the menu will be added to the menubar itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 SUBMENU is the new menu to add.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 See the documentation of `current-menubar' for the syntax.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 BEFORE, if provided, is the name of a menu before which this menu should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 be added, if this menu is not on its parent already. If the menu is already
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
314 present, it will not be moved.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
315 IN-MENU, if provided, means use that instead of `current-menubar' as the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
316 menu to change."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (check-menu-syntax submenu nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (add-menu-item-1 nil menu-path submenu before in-menu))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
319 ;; purespace is no more, so this function is unnecessary
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
320 ;(defun purecopy-menubar (x)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
321 ; ;; this calls purecopy on the strings, and the contents of the vectors,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
322 ; ;; but not on the vectors themselves, or the conses - those must be
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
323 ; ;; writable.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
324 ; (cond ((vectorp x)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
325 ; (let ((i (length x)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
326 ; (while (> i 0)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
327 ; (aset x (1- i) (purecopy (aref x (1- i))))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
328 ; (setq i (1- i))))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
329 ; x)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
330 ; ((consp x)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
331 ; (let ((rest x))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
332 ; (while rest
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
333 ; (setcar rest (purecopy-menubar (car rest)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
334 ; (setq rest (cdr rest))))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
335 ; x)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
336 ; (t
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
337 ; (purecopy x))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (defun delete-menu-item (path &optional from-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 "Remove the named menu item from the menu hierarchy.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
341 PATH is a list of strings which identify the position of the menu item
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
342 in the menu hierarchy. The documentation of `add-submenu' describes
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
343 menu paths.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
344 FROM-MENU, if provided, means use that instead of `current-menubar'
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
345 as the menu to change."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (let* ((pair (condition-case nil (find-menu-item (or from-menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 current-menubar) path)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (error nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (item (car pair))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (parent (or (cdr pair) current-menubar)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (if (not item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 ;; the menubar is the only special case, because other menus begin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 ;; with their name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (if (eq parent current-menubar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (setq current-menubar (delq item parent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (delq item parent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (set-menubar-dirty-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 item)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (defun relabel-menu-item (path new-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 "Change the string of the specified menu item.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
363 PATH is a list of strings which identify the position of the menu item in
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
365 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 NEW-NAME is the string that the menu item will be printed as from now on."
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
368 (check-type new-name string)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (let* ((menubar current-menubar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (pair (find-menu-item menubar path))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 (item (car pair))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (menu (cdr pair)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (or item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (signal 'error (list (if menu (gettext "No such menu item")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (gettext "No such menu"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 path)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (if (and (consp item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (stringp (car item)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (setcar item new-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 (aset item 0 new-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 (set-menubar-dirty-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 ;; these are all bad style. Why in the world would we put evaluable forms
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 ;; into the menubar if we didn't want people to use 'em?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 ;; x-font-menu.el is the only known offender right now and that ought to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 ;; rehashed a bit.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
390 ;;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 (defun enable-menu-item-1 (path toggle-p on-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (let (menu item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 (if (and (vectorp path) (> (length path) 2)) ; limited syntax checking...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (setq item path)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 (let* ((menubar current-menubar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (pair (find-menu-item menubar path)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 (setq item (car pair)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 menu (cdr pair))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (or item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (signal 'error (list (if menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 "No such menu item"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 "No such menu")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 path)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (if (consp item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (error "%S is a menu, not a menu item" path))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 (if (or (> (length item) 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (and (symbolp (aref item 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (= ?: (aref (symbol-name (aref item 2)) 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 ;; plist-like syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (let ((i 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 (keyword (if toggle-p :selected :active))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (ok nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (while (< i (length item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (cond ((eq (aref item i) keyword)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (aset item (1+ i) on-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (setq ok t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (setq i (+ i 2)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 (cond (ok nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 (toggle-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (signal 'error (list "not a toggle menu item" item)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 ;; Need to copy the item to extend it, sigh...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (let ((cons (memq item menu))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (new-item (vconcat item (list keyword on-p))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 (if cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 (setcar cons (setq item new-item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 (if menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (error "couldn't find %S on its parent?" item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (error "no %S slot to set: %S" keyword item)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 ;; positional syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (if toggle-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 (signal 'error (list "not a toggle menu item" item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 (aset item 2 on-p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 (set-menubar-dirty-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (defun enable-menu-item (path)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 "Make the named menu item be selectable.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
440 PATH is a list of strings which identify the position of the menu item in
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
442 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 (enable-menu-item-1 path nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 (defun disable-menu-item (path)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 "Make the named menu item be unselectable.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
448 PATH is a list of strings which identify the position of the menu item in
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
450 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 (enable-menu-item-1 path nil nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 (defun select-toggle-menu-item (path)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 "Make the named toggle- or radio-style menu item be in the `selected' state.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
456 PATH is a list of strings which identify the position of the menu item in
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
458 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 (enable-menu-item-1 path t t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 (defun deselect-toggle-menu-item (path)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 "Make the named toggle- or radio-style menu item be in the `unselected' state.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
464 PATH is a list of strings which identify the position of the menu item in
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 the menu hierarchy. (\"File\" \"Save\") means the menu item called \"Save\"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
466 under the toplevel \"File\" menu. (\"Menu\" \"Foo\" \"Item\") means the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 menu item called \"Item\" under the \"Foo\" submenu of \"Menu\"."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 (enable-menu-item-1 path t nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470
2545
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
471 ;;; functions for manipulating whole menus -- adding accelerators, sorting,
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
472 ;;; splitting long menus, etc.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
473
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
474 (defun submenu-generate-accelerator-spec (list &optional omit-chars-list)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
475 "Add auto-generated accelerator specifications to a submenu.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
476 This can be used to add accelerators to the return value of a menu filter
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
477 function. It correctly ignores unselectable items. It will destructively
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
478 modify the list passed to it. If an item already has an auto-generated
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
479 accelerator spec, this will be removed before the new one is added, making
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
480 this function idempotent.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
481
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
482 If OMIT-CHARS-LIST is given, it should be a list of lowercase characters,
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
483 which will not be used as accelerators."
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
484 (let ((n 0))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
485 (dolist (item list list)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
486 (cond
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
487 ((or (vectorp item) (consp item))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
488 (incf n)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
489 (setf (elt item 0)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
490 (concat
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
491 (menu-item-generate-accelerator-spec n omit-chars-list)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
492 (menu-item-strip-accelerator-spec (elt item 0)))))))))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
493
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
494 (defun menu-item-strip-accelerator-spec (item)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
495 "Strip an auto-generated accelerator spec off of ITEM.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
496 ITEM should be a string. This removes specs added by
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
497 `menu-item-generate-accelerator-spec' and `submenu-generate-accelerator-spec'."
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
498 (if (string-match "%_. " item)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
499 (substring item 4)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
500 item))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
501
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
502 (defun menu-item-generate-accelerator-spec (n &optional omit-chars-list)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
503 "Return an accelerator specification for use with auto-generated menus.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
504 This should be concat'd onto the beginning of each menu line. The spec
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
505 allows the Nth line to be selected by the number N. '0' is used for the
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
506 10th line, and 'a' through 'z' are used for the following 26 lines.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
507
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
508 If OMIT-CHARS-LIST is given, it should be a list of lowercase characters,
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
509 which will not be used as accelerators."
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
510 (cond ((< n 10) (concat "%_" (int-to-string n) " "))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
511 ((= n 10) "%_0 ")
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
512 ((<= n 36)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
513 (setq n (- n 10))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
514 (let ((m 0))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
515 (while (> n 0)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
516 (setq m (1+ m))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
517 (while (memq (int-to-char (+ m (- (char-to-int ?a) 1)))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
518 omit-chars-list)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
519 (setq m (1+ m)))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
520 (setq n (1- n)))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
521 (if (<= m 26)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
522 (concat
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
523 "%_"
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
524 (char-to-string (int-to-char (+ m (- (char-to-int ?a) 1))))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
525 " ")
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
526 "")))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
527 (t "")))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
528
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
529 (defcustom menu-max-items 25
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
530 "*Maximum number of items in generated menus.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
531 If number of entries in such a menu is larger than this value, split menu
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
532 into submenus of nearly equal length (see `menu-submenu-max-items'). If
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
533 nil, never split menu into submenus."
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
534 :group 'menu
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
535 :type '(choice (const :tag "no submenus" nil)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
536 (integer)))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
537
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
538 (defcustom menu-submenu-max-items 20
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
539 "*Maximum number of items in submenus when splitting menus.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
540 We split large menus into submenus of this many items, and then balance
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
541 them out as much as possible (otherwise the last submenu may have very few
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
542 items)."
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
543 :group 'menu
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
544 :type 'integer)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
545
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
546 (defcustom menu-submenu-name-format "%-12.12s ... %.12s"
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
547 "*Format specification of the submenu name when splitting menus.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
548 Used by `menu-split-long-menu' if the number of entries in a menu is
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
549 larger than `menu-menu-max-items'.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
550 This string should contain one %s for the name of the first entry and
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
551 one %s for the name of the last entry in the submenu.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
552 If the value is a function, it should return the submenu name. The
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
553 function is be called with two arguments, the names of the first and
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
554 the last entry in the menu."
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
555 :group 'menu
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
556 :type '(choice (string :tag "Format string")
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
557 (function)))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
558
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
559 (defun menu-split-long-menu-and-sort (menu)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
560 "Sort MENU, split according to `menu-max-items' and add accelerator specs.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
561 This is useful for menus generated by filter functions, to make them look
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
562 nice. This is equivalent to
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
563
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
564 \(menu-split-long-menu (menu-sort-menu menu))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
565
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
566 and you can call those functions individually if necessary.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
567 You can also call `submenu-generate-accelerator-spec' yourself to add
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
568 accelerator specs -- this works even if the specs have already been added."
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
569 (menu-split-long-menu (menu-sort-menu menu)))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
570
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
571 (defun menu-split-long-menu (menu)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
572 "Split MENU according to `menu-max-items' and add accelerator specs.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
573 If MENU already has accelerator specs, they will be removed and new ones
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
574 generated. You should normally use `menu-split-long-menu-and-sort' instead.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
575 The menu should already be sorted to get meaningful results when it is
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
576 split, since the outer menus are of the format `FROM ... TO'."
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
577 (let ((len (length menu)))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
578 (if (or (null menu-max-items)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
579 (<= len menu-max-items))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
580 (submenu-generate-accelerator-spec menu)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
581 (let* ((outer (/ (+ len (1- menu-submenu-max-items))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
582 menu-submenu-max-items))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
583 (inner (/ (+ len (1- outer)) outer))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
584 (result nil))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
585 (while menu
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
586 (let ((sub nil)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
587 (from (car menu)))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
588 (dotimes (foo (min inner len))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
589 (setq sub (cons (car menu) sub)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
590 menu (cdr menu)))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
591 (setq len (- len inner))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
592 (let* ((to (car sub))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
593 (ftext (menu-item-strip-accelerator-spec
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
594 (menu-item-text from)))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
595 (ttext (menu-item-strip-accelerator-spec
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
596 (menu-item-text to))))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
597 (setq sub (nreverse sub))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
598 (setq result
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
599 (cons (cons (if (stringp menu-submenu-name-format)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
600 (format menu-submenu-name-format
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
601 ftext ttext)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
602 (funcall menu-submenu-name-format
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
603 ftext ttext))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
604 (submenu-generate-accelerator-spec sub))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
605 result)))))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
606 (submenu-generate-accelerator-spec (nreverse result))))))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
607
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
608 (defun menu-sort-menu (menu)
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
609 "Sort MENU alphabetically.
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
610 You should normally use `menu-split-long-menu-and-sort' instead."
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
611 (sort menu
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
612 #'(lambda (a b) (< (compare-menu-text
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
613 (menu-item-text a) (menu-item-text b))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
614 0))))
9caf26dd924f [xemacs-hg @ 2005-02-03 05:03:36 by ben]
ben
parents: 707
diff changeset
615
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
616
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
617 ;;;;;;; popup menus
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
618
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
619 (defvar global-popup-menu nil
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
620 "The global popup menu. This is present in all modes.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
621 See the function `popup-menu' for a description of menu syntax.")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
622
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
623 (defvar mode-popup-menu nil
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
624 "The mode-specific popup menu. Automatically buffer local.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
625 This is appended to the default items in `global-popup-menu'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
626 See the function `popup-menu' for a description of menu syntax.")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
627 (make-variable-buffer-local 'mode-popup-menu)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
628
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
629 (defvar activate-popup-menu-hook nil
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
630 "Function or functions run before a mode-specific popup menu is made visible.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
631 These functions are called with no arguments, and should interrogate and
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
632 modify the value of `global-popup-menu' or `mode-popup-menu' as desired.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
633 Note: this hook is only run if you use `popup-mode-menu' for activating the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
634 global and mode-specific commands; if you have your own binding for button3,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
635 this hook won't be run.")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
636
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
637 (defvar last-popup-menu-event nil
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
638 "The mouse event that invoked the last popup menu.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
639 NOTE: This is EXPERIMENTAL and may change at any time.")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
640
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
641 (defun popup-mode-menu (&optional event)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
642 "Pop up a menu of global and mode-specific commands.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
643 The menu is computed by combining `global-popup-menu' and `mode-popup-menu'
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
644 with any items derived from the `context-menu' property of the extent where the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
645 button was clicked."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
646 (interactive "_e")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
647 (setq last-popup-menu-event
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
648 (or (and event (button-event-p event) event)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
649 (let* ((mouse-pos (mouse-position))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
650 (win (car mouse-pos))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
651 (x (cadr mouse-pos))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
652 (y (cddr mouse-pos))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
653 (edges (window-pixel-edges win))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
654 (winx (first edges))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
655 (winy (second edges))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
656 (x (+ x winx))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
657 (y (+ y winy)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
658 (make-event 'button-press
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
659 `(button 3 x ,x y ,y channel ,(window-frame win)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
660 timestamp ,(current-event-timestamp
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
661 (cdfw-console win)))))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
662 (run-hooks 'activate-popup-menu-hook)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
663 (let* ((context-window (and event (event-window event)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
664 (context-point (and event (event-point event)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
665 (context-extents (and context-window
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
666 context-point
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
667 (extents-at context-point
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
668 (window-buffer context-window)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
669 'context-menu)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
670 (context-menu-items
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
671 (apply 'append (mapcar #'(lambda (extent)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
672 (extent-property extent 'context-menu))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
673 context-extents))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
674 (popup-menu
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
675 (progn
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
676 ;; Merge global-popup-menu and mode-popup-menu
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
677 (and mode-popup-menu (check-menu-syntax mode-popup-menu))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
678 (let* ((mode-title (and (stringp (car mode-popup-menu))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
679 (car mode-popup-menu)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
680 (mode-items (if mode-title (cdr mode-popup-menu)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
681 mode-popup-menu))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
682 (global-title (and (stringp (car global-popup-menu))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
683 (car global-popup-menu)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
684 (global-items (if global-title (cdr global-popup-menu)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
685 global-popup-menu))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
686 mode-filters)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
687 ;; Strip keywords from local menu for attaching them at the top
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
688 (while (and mode-items
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
689 (keywordp (car mode-items)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
690 ;; Push both keyword and its argument.
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
691 (push (pop mode-items) mode-filters)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
692 (push (pop mode-items) mode-filters))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
693 (setq mode-filters (nreverse mode-filters))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
694 ;; If mode-filters contains a keyword already present in
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
695 ;; `global-popup-menu', you will probably lose.
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
696 (append (and popup-menu-titles
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
697 (cond (mode-title (list mode-title))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
698 (global-title (list global-title))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
699 (t "")))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
700 mode-filters
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
701 context-menu-items
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
702 (and context-menu-items mode-items '("---"))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
703 mode-items
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
704 (and (or context-menu-items mode-items)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
705 global-items '("---" "---"))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
706 (and global-title (list global-title))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
707 global-items
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 446
diff changeset
708 ))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
709
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
710 (while (popup-up-p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
711 (dispatch-event (next-event)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
712
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
713 ))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
714
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
715 (defun popup-buffer-menu (event)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
716 "Pop up a copy of the menubar Buffers menu where the mouse is clicked."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
717 (interactive "e")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
718 (let ((window (and (event-over-text-area-p event) (event-window event)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
719 (bmenu nil))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
720 (or window
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
721 (error "Pointer must be in a normal window"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
722 (select-window window)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
723 (if current-menubar
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
724 (setq bmenu (assoc "%_Buffers" current-menubar)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
725 (if (null bmenu)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
726 (setq bmenu (assoc "%_Buffers" default-menubar)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
727 (if (null bmenu)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
728 (error "Can't find the Buffers menu"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
729 (popup-menu bmenu)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
730
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
731 (defun popup-menubar-menu (event)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
732 "Pop up a copy of menu that also appears in the menubar."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
733 (interactive "e")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
734 (let ((window (and (event-over-text-area-p event) (event-window event)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
735 popup-menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
736 (or window
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
737 (error "Pointer must be in a normal window"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
738 (select-window window)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
739 (and current-menubar (run-hooks 'activate-menubar-hook))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
740 ;; #### Instead of having to copy this just to safely get rid of
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
741 ;; any nil what we should really do is fix up the internal menubar
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
742 ;; code to just ignore nil if generating a popup menu
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
743 (setq popup-menubar (delete nil (copy-sequence (or current-menubar
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
744 default-menubar))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
745 (popup-menu (cons "%_Menubar Menu" popup-menubar))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
746 ))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
747
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
748 (defun menu-call-at-event (form &optional event default-behavior-fallback)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
749 "Call FORM while temporarily setting point to the position in EVENT.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
750 NOTE: This is EXPERIMENTAL and may change at any time.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
751
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
752 FORM is called the way forms in menu specs are: i.e. if a symbol, it's called
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
753 with `call-interactively', otherwise with `eval'. EVENT defaults to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
754 `last-popup-menu-event', making this function especially useful in popup
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
755 menus. The buffer and point are set temporarily within a `save-excursion'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
756 If EVENT is not a mouse event, or was not over a buffer, nothing
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
757 happens unless DEFAULT-BEHAVIOR-FALLBACK is non-nil, in which case the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
758 FORM is called normally."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
759 (or event (setq event last-popup-menu-event))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
760 (let ((buf (event-buffer event))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
761 (p (event-closest-point event)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
762 (cond ((and buf p (> p 0))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
763 (save-excursion
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
764 (set-buffer buf)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
765 (goto-char p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
766 (if (symbolp form)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
767 (call-interactively form)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
768 (eval form))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
769 (default-behavior-fallback
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
770 (if (symbolp form)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
771 (call-interactively form)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
772 (eval form))))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
773
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
774 (global-set-key 'button3 'popup-mode-menu)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
775 ;; shift button3 and shift button2 are reserved for Hyperbole
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
776 (global-set-key '(meta control button3) 'popup-buffer-menu)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
777 ;; The following command is way too dangerous with Custom.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
778 ;; (global-set-key '(meta shift button3) 'popup-menubar-menu)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
779
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
780 ;; Here's a test of the cool new menu features (from Stig).
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
781
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
782 ;;(setq mode-popup-menu
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
783 ;; '("Test Popup Menu"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
784 ;; :filter cdr
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
785 ;; ["this item won't appear because of the menu filter" ding t]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
786 ;; "--:singleLine"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
787 ;; "singleLine"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
788 ;; "--:doubleLine"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
789 ;; "doubleLine"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
790 ;; "--:singleDashedLine"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
791 ;; "singleDashedLine"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
792 ;; "--:doubleDashedLine"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
793 ;; "doubleDashedLine"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
794 ;; "--:noLine"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
795 ;; "noLine"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
796 ;; "--:shadowEtchedIn"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
797 ;; "shadowEtchedIn"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
798 ;; "--:shadowEtchedOut"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
799 ;; "shadowEtchedOut"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
800 ;; "--:shadowDoubleEtchedIn"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
801 ;; "shadowDoubleEtchedIn"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
802 ;; "--:shadowDoubleEtchedOut"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
803 ;; "shadowDoubleEtchedOut"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
804 ;; "--:shadowEtchedInDash"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
805 ;; "shadowEtchedInDash"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
806 ;; "--:shadowEtchedOutDash"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
807 ;; "shadowEtchedOutDash"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
808 ;; "--:shadowDoubleEtchedInDash"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
809 ;; "shadowDoubleEtchedInDash"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
810 ;; "--:shadowDoubleEtchedOutDash"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
811 ;; "shadowDoubleEtchedOutDash"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
812 ;; ))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
813
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 (defun get-popup-menu-response (menu-desc &optional event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 "Pop up the given menu and wait for a response.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 This blocks until the response is received, and returns the misc-user
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 event that encapsulates the response. To execute it, you can do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 (funcall (event-function response) (event-object response))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 If no response was received, nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 MENU-DESC and EVENT are as in the call to `popup-menu'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 ;; partially stolen from w3
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
823
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
824 ;; This function is way gross and assumes to much about menu
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
825 ;; processing that is X specific. Under mswindows popup menus behave
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
826 ;; in reasonable ways that you can't obstruct.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 (let ((echo-keystrokes 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 new-event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 (popup-menu menu-desc event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 (catch 'popup-done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 (while t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 (setq new-event (next-command-event new-event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 (cond ((misc-user-event-p new-event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 (throw 'popup-done new-event))
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
835 ((button-release-event-p new-event);; don't beep twice
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
836 nil)
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
837 ;; It shows how bogus this function is that the event
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
838 ;; arg could be missing and no-one noticed ...
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
839 ((event-matches-key-specifier-p new-event (quit-char))
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
840 (signal 'quit nil))
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
841 ;; mswindows has no pop-down processing (selection is
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
842 ;; atomic) so doing anything more makes no sense. Since
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
843 ;; popup-up-p is always false under mswindows, this
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
844 ;; function has been ordered to do essentially X-specifc
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
845 ;; processing after this check.
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
846 ((not (popup-up-p))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 (setq unread-command-events (cons new-event
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 unread-command-events))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 (throw 'popup-done nil))
707
a307f9a2021d [xemacs-hg @ 2001-12-20 05:49:28 by andyp]
andyp
parents: 502
diff changeset
850 ;; mswindows never gets here
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 (beep)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 (message "please make a choice from the menu.")))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 (defun popup-menu-and-execute-in-window (menu-desc event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 "Pop up the given menu and execute its response in EVENT's window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 This blocks until the response is received, temporarily selects
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 EVENT's window, and executes the command specified in the response.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 EVENT can also be a window. See `popup-menu' for the semantics of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 MENU-DESC."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 (let ((response
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 (get-popup-menu-response menu-desc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 (and (eventp event) event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 (and (misc-user-event-p response)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 (save-selected-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 (select-window (if (windowp event) event
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 (event-window event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 (funcall (event-function response)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 (event-object response))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 ;; provide default bindings for menu accelerator map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 (and (boundp 'menu-accelerator-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 (keymapp menu-accelerator-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 (define-key menu-accelerator-map "\e" 'menu-escape)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 (define-key menu-accelerator-map [left] 'menu-left)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 (define-key menu-accelerator-map [right] 'menu-right)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 (define-key menu-accelerator-map [up] 'menu-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 (define-key menu-accelerator-map [down] 'menu-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 (define-key menu-accelerator-map [return] 'menu-select)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
881 (define-key menu-accelerator-map [kp-down] 'menu-down)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
882 (define-key menu-accelerator-map [kp-up] 'menu-down)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
883 (define-key menu-accelerator-map [kp-left] 'menu-left)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
884 (define-key menu-accelerator-map [kp-right] 'menu-right)
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
885 (define-key menu-accelerator-map [kp-enter] 'menu-select)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 (define-key menu-accelerator-map "\C-g" 'menu-quit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 (provide 'menubar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 ;;; menubar.el ends here