annotate lisp/easy-mmode.el @ 4981:4aebb0131297

Cleanups/renaming of EXTERNAL_TO_C_STRING and friends -------------------- ChangeLog entries follow: -------------------- modules/ChangeLog addition: 2010-02-05 Ben Wing <ben@xemacs.org> * postgresql/postgresql.c: * postgresql/postgresql.c (CHECK_LIVE_CONNECTION): * postgresql/postgresql.c (Fpq_connectdb): * postgresql/postgresql.c (Fpq_connect_start): * postgresql/postgresql.c (Fpq_lo_import): * postgresql/postgresql.c (Fpq_lo_export): * ldap/eldap.c (Fldap_open): * ldap/eldap.c (Fldap_search_basic): * ldap/eldap.c (Fldap_add): * ldap/eldap.c (Fldap_modify): * ldap/eldap.c (Fldap_delete): * canna/canna_api.c (Fcanna_initialize): * canna/canna_api.c (Fcanna_store_yomi): * canna/canna_api.c (Fcanna_parse): * canna/canna_api.c (Fcanna_henkan_begin): EXTERNAL_TO_C_STRING returns its argument instead of storing it in a parameter, and is renamed to EXTERNAL_TO_ITEXT. Similar things happen to related macros. See entry in src/ChangeLog. More Mule-izing of postgresql.c. Extract out common code between `pq-connectdb' and `pq-connect-start'. Fix places that signal an error string using a formatted string to instead follow the standard and have a fixed reason followed by the particular error message stored as one of the frobs. src/ChangeLog addition: 2010-02-05 Ben Wing <ben@xemacs.org> * console-msw.c (write_string_to_mswindows_debugging_output): * console-msw.c (Fmswindows_message_box): * console-x.c (x_perhaps_init_unseen_key_defaults): * console.c: * database.c (dbm_get): * database.c (dbm_put): * database.c (dbm_remove): * database.c (berkdb_get): * database.c (berkdb_put): * database.c (berkdb_remove): * database.c (Fopen_database): * device-gtk.c (gtk_init_device): * device-msw.c (msprinter_init_device_internal): * device-msw.c (msprinter_default_printer): * device-msw.c (msprinter_init_device): * device-msw.c (sync_printer_with_devmode): * device-msw.c (Fmsprinter_select_settings): * device-x.c (sanity_check_geometry_resource): * device-x.c (Dynarr_add_validified_lisp_string): * device-x.c (x_init_device): * device-x.c (Fx_put_resource): * device-x.c (Fx_valid_keysym_name_p): * device-x.c (Fx_set_font_path): * dialog-msw.c (push_lisp_string_as_unicode): * dialog-msw.c (handle_directory_dialog_box): * dialog-msw.c (handle_file_dialog_box): * dialog-x.c (dbox_descriptor_to_widget_value): * editfns.c (Fformat_time_string): * editfns.c (Fencode_time): * editfns.c (Fset_time_zone_rule): * emacs.c (make_argc_argv): * emacs.c (Fdump_emacs): * emodules.c (emodules_load): * eval.c: * eval.c (maybe_signal_error_1): * event-msw.c (Fdde_alloc_advise_item): * event-msw.c (mswindows_dde_callback): * event-msw.c (mswindows_wnd_proc): * fileio.c (report_error_with_errno): * fileio.c (Fsysnetunam): * fileio.c (Fdo_auto_save): * font-mgr.c (extract_fcapi_string): * font-mgr.c (Ffc_config_app_font_add_file): * font-mgr.c (Ffc_config_app_font_add_dir): * font-mgr.c (Ffc_config_filename): * frame-gtk.c (gtk_set_frame_text_value): * frame-gtk.c (gtk_create_widgets): * frame-msw.c (mswindows_init_frame_1): * frame-msw.c (mswindows_set_title_from_ibyte): * frame-msw.c (msprinter_init_frame_3): * frame-x.c (x_set_frame_text_value): * frame-x.c (x_set_frame_properties): * frame-x.c (start_drag_internal_1): * frame-x.c (x_cde_transfer_callback): * frame-x.c (x_create_widgets): * glyphs-eimage.c (my_jpeg_output_message): * glyphs-eimage.c (jpeg_instantiate): * glyphs-eimage.c (gif_instantiate): * glyphs-eimage.c (png_instantiate): * glyphs-eimage.c (tiff_instantiate): * glyphs-gtk.c (xbm_instantiate_1): * glyphs-gtk.c (gtk_xbm_instantiate): * glyphs-gtk.c (gtk_xpm_instantiate): * glyphs-gtk.c (gtk_xface_instantiate): * glyphs-gtk.c (cursor_font_instantiate): * glyphs-gtk.c (gtk_redisplay_widget): * glyphs-gtk.c (gtk_widget_instantiate_1): * glyphs-gtk.c (gtk_add_tab_item): * glyphs-msw.c (mswindows_xpm_instantiate): * glyphs-msw.c (bmp_instantiate): * glyphs-msw.c (mswindows_resource_instantiate): * glyphs-msw.c (xbm_instantiate_1): * glyphs-msw.c (mswindows_xbm_instantiate): * glyphs-msw.c (mswindows_xface_instantiate): * glyphs-msw.c (mswindows_redisplay_widget): * glyphs-msw.c (mswindows_widget_instantiate): * glyphs-msw.c (add_tree_item): * glyphs-msw.c (add_tab_item): * glyphs-msw.c (mswindows_combo_box_instantiate): * glyphs-msw.c (mswindows_widget_query_string_geometry): * glyphs-x.c (x_locate_pixmap_file): * glyphs-x.c (xbm_instantiate_1): * glyphs-x.c (x_xbm_instantiate): * glyphs-x.c (extract_xpm_color_names): * glyphs-x.c (x_xpm_instantiate): * glyphs-x.c (x_xface_instantiate): * glyphs-x.c (autodetect_instantiate): * glyphs-x.c (safe_XLoadFont): * glyphs-x.c (cursor_font_instantiate): * glyphs-x.c (x_redisplay_widget): * glyphs-x.c (Fchange_subwindow_property): * glyphs-x.c (x_widget_instantiate): * glyphs-x.c (x_tab_control_redisplay): * glyphs.c (pixmap_to_lisp_data): * gui-x.c (menu_separator_style_and_to_external): * gui-x.c (add_accel_and_to_external): * gui-x.c (button_item_to_widget_value): * hpplay.c (player_error_internal): * hpplay.c (play_sound_file): * hpplay.c (play_sound_data): * intl.c (Fset_current_locale): * lisp.h: * menubar-gtk.c (gtk_xemacs_set_accel_keys): * menubar-msw.c (populate_menu_add_item): * menubar-msw.c (populate_or_checksum_helper): * menubar-x.c (menu_item_descriptor_to_widget_value_1): * nt.c (init_user_info): * nt.c (get_long_basename): * nt.c (nt_get_resource): * nt.c (init_mswindows_environment): * nt.c (get_cached_volume_information): * nt.c (mswindows_readdir): * nt.c (read_unc_volume): * nt.c (mswindows_stat): * nt.c (mswindows_getdcwd): * nt.c (mswindows_executable_type): * nt.c (Fmswindows_short_file_name): * ntplay.c (nt_play_sound_file): * objects-gtk.c: * objects-gtk.c (gtk_valid_color_name_p): * objects-gtk.c (gtk_initialize_font_instance): * objects-gtk.c (gtk_font_list): * objects-msw.c (font_enum_callback_2): * objects-msw.c (parse_font_spec): * objects-x.c (x_parse_nearest_color): * objects-x.c (x_valid_color_name_p): * objects-x.c (x_initialize_font_instance): * objects-x.c (x_font_instance_truename): * objects-x.c (x_font_list): * objects-xlike-inc.c (XFUN): * objects-xlike-inc.c (xft_find_charset_font): * process-nt.c (mswindows_report_winsock_error): * process-nt.c (nt_create_process): * process-nt.c (get_internet_address): * process-nt.c (nt_open_network_stream): * process-unix.c: * process-unix.c (allocate_pty): * process-unix.c (get_internet_address): * process-unix.c (unix_canonicalize_host_name): * process-unix.c (unix_open_network_stream): * realpath.c: * select-common.h (lisp_data_to_selection_data): * select-gtk.c (symbol_to_gtk_atom): * select-gtk.c (atom_to_symbol): * select-msw.c (symbol_to_ms_cf): * select-msw.c (mswindows_register_selection_data_type): * select-x.c (symbol_to_x_atom): * select-x.c (x_atom_to_symbol): * select-x.c (hack_motif_clipboard_selection): * select-x.c (Fx_store_cutbuffer_internal): * sound.c (Fplay_sound_file): * sound.c (Fplay_sound): * sound.h (sound_perror): * sysdep.c: * sysdep.c (qxe_allocating_getcwd): * sysdep.c (qxe_execve): * sysdep.c (copy_in_passwd): * sysdep.c (qxe_getpwnam): * sysdep.c (qxe_ctime): * sysdll.c (dll_open): * sysdll.c (dll_function): * sysdll.c (dll_variable): * sysdll.c (search_linked_libs): * sysdll.c (dll_error): * sysfile.h: * sysfile.h (PATHNAME_CONVERT_OUT_TSTR): * sysfile.h (PATHNAME_CONVERT_OUT_UTF_8): * sysfile.h (PATHNAME_CONVERT_OUT): * sysfile.h (LISP_PATHNAME_CONVERT_OUT): * syswindows.h (ITEXT_TO_TSTR): * syswindows.h (LOCAL_FILE_FORMAT_TO_TSTR): * syswindows.h (TSTR_TO_LOCAL_FILE_FORMAT): * syswindows.h (LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN): * syswindows.h (LISP_LOCAL_FILE_FORMAT_MAYBE_URL_TO_TSTR): * text.h: * text.h (eicpy_ext_len): * text.h (enum new_dfc_src_type): * text.h (EXTERNAL_TO_ITEXT): * text.h (GET_STRERROR): * tooltalk.c (check_status): * tooltalk.c (Fadd_tooltalk_message_arg): * tooltalk.c (Fadd_tooltalk_pattern_attribute): * tooltalk.c (Fadd_tooltalk_pattern_arg): * win32.c (tstr_to_local_file_format): * win32.c (mswindows_lisp_error_1): * win32.c (mswindows_report_process_error): * win32.c (Fmswindows_shell_execute): * win32.c (mswindows_read_link_1): Changes involving external/internal format conversion, mostly code cleanup and renaming. 1. Eliminate the previous macros like LISP_STRING_TO_EXTERNAL that stored its result in a parameter. The new version of LISP_STRING_TO_EXTERNAL returns its result through the return value, same as the previous NEW_LISP_STRING_TO_EXTERNAL. Use the new-style macros throughout the code. 2. Rename C_STRING_TO_EXTERNAL and friends to ITEXT_TO_EXTERNAL, in keeping with overall naming rationalization involving Itext and related types. Macros involved in previous two: EXTERNAL_TO_C_STRING -> EXTERNAL_TO_ITEXT EXTERNAL_TO_C_STRING_MALLOC -> EXTERNAL_TO_ITEXT_MALLOC SIZED_EXTERNAL_TO_C_STRING -> SIZED_EXTERNAL_TO_ITEXT SIZED_EXTERNAL_TO_C_STRING_MALLOC -> SIZED_EXTERNAL_TO_ITEXT_MALLOC C_STRING_TO_EXTERNAL -> ITEXT_TO_EXTERNAL C_STRING_TO_EXTERNAL_MALLOC -> ITEXT_TO_EXTERNAL_MALLOC LISP_STRING_TO_EXTERNAL LISP_STRING_TO_EXTERNAL_MALLOC LISP_STRING_TO_TSTR C_STRING_TO_TSTR -> ITEXT_TO_TSTR TSTR_TO_C_STRING -> TSTR_TO_ITEXT The following four still return their values through parameters, since they have more than one value to return: C_STRING_TO_SIZED_EXTERNAL -> ITEXT_TO_SIZED_EXTERNAL LISP_STRING_TO_SIZED_EXTERNAL C_STRING_TO_SIZED_EXTERNAL_MALLOC -> ITEXT_TO_SIZED_EXTERNAL_MALLOC LISP_STRING_TO_SIZED_EXTERNAL_MALLOC Sometimes additional casts had to be inserted, since the old macros played strange games and completely defeated the type system of the store params. 3. Rewrite many places where direct calls to TO_EXTERNAL_FORMAT occurred with calls to one of the convenience macros listed above, or to make_extstring(). 4. Eliminate SIZED_C_STRING macros (they were hardly used, anyway) and use a direct call to TO_EXTERNAL_FORMAT or TO_INTERNAL_FORMAT. 4. Use LISP_PATHNAME_CONVERT_OUT in many places instead of something like LISP_STRING_TO_EXTERNAL(..., Qfile_name). 5. Eliminate some temporary variables that are no longer necessary now that we return a value rather than storing it into a variable. 6. Some Mule-izing in database.c. 7. Error functions: -- A bit of code cleanup in maybe_signal_error_1. -- Eliminate report_file_type_error; it's just an alias for signal_error_2 with params in a different order. -- Fix some places in the hostname-handling code that directly inserted externally-retrieved error strings into the supposed ASCII "reason" param instead of doing the right thing and sticking text descriptive of what was going on in "reason" and putting the external message in a frob. 8. Use Ascbyte instead of CIbyte in process-unix.c and maybe one or two other places. 9. Some code cleanup in copy_in_passwd() in sysdep.c. 10. Fix a real bug due to accidental variable shadowing in tstr_to_local_file_format() in win32.c.
author Ben Wing <ben@xemacs.org>
date Fri, 05 Feb 2010 11:02:24 -0600
parents e29fcfd8df5f
children 308d34e9f07d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2548
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
1 ;;; easy-mmode.el --- easy definition for major and minor modes
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
2
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
3 ;; Copyright (C) 1997, 2000, 2001 Free Software Foundation, Inc.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
4
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
5 ;; Author: Georges Brun-Cottan <Georges.Brun-Cottan@inria.fr>
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
6 ;; Maintainer: Stefan Monnier <monnier@gnu.org>
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
7
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
8 ;; Keywords: extensions lisp
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
9
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
10 ;; This file is part of XEmacs.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
11
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
12 ;; XEmacs is free software; you can redistribute it and/or modify
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
15 ;; any later version.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
16
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful,
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
20 ;; GNU General Public License for more details.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
21
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
23 ;; along with XEmacs; see the file COPYING. If not, write to the
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
26
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
27 ;;; Synched up with: GNU Emacs 21.3.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
28
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
29 ;;; Commentary:
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
30
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
31 ;; Minor modes are useful and common. This package makes defining a
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
32 ;; minor mode easy, by focusing on the writing of the minor mode
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
33 ;; functionalities themselves. Moreover, this package enforces a
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
34 ;; conventional naming of user interface primitives, making things
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
35 ;; natural for the minor-mode end-users.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
36
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
37 ;; For each mode, easy-mmode defines the following:
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
38 ;; <mode> : The minor mode predicate. A buffer-local variable.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
39 ;; <mode>-map : The keymap possibly associated to <mode>.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
40 ;; <mode>-hook,<mode>-on-hook,<mode>-off-hook and <mode>-mode:
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
41 ;; see `define-minor-mode' documentation
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
42 ;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
43 ;; eval
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
44 ;; (pp (macroexpand '(define-minor-mode <your-mode> <doc>)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
45 ;; to check the result before using it.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
46
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
47 ;; The order in which minor modes are installed is important. Keymap
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
48 ;; lookup proceeds down minor-mode-map-alist, and the order there
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
49 ;; tends to be the reverse of the order in which the modes were
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
50 ;; installed. Perhaps there should be a feature to let you specify
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
51 ;; orderings.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
52
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
53 ;; Additionally to `define-minor-mode', the package provides convenient
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
54 ;; ways to define keymaps, and other helper functions for major and minor
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
55 ;; modes.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
56
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
57 ;;; Code:
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
58
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
59 (eval-when-compile (require 'cl))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
60
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
61 ;;; This file uses two functions that did not exist in some versions of
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
62 ;;; XEmacs: propertize and replace-regexp-in-string. We provide these
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
63 ;;; functions here for such XEmacsen.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
64 ;;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
65 ;;; FIXME: These function definitions should go into the future or
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
66 ;;; forward-compat package, once that package exists.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
67
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
68 ;; XEmacs <= 21.4 does not have propertize, but XEmacs >= 21.5 dumps it (it is
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
69 ;; defined in subr.el). Therefore, it is either defined regardless of what
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
70 ;; has been loaded already, or it won't be defined regardless of what is
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
71 ;; loaded.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
72 (if (not (fboundp 'propertize))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
73 (defun propertize (string &rest properties)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
74 "Return a copy of STRING with text properties added.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
75 First argument is the string to copy.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
76 Remaining arguments form a sequence of PROPERTY VALUE pairs for text
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
77 properties to add to the result."
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
78 (let ((str (copy-sequence string)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
79 (add-text-properties 0 (length str)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
80 properties
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
81 str)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
82 str)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
83
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
84 ;; XEmacs <= 21.4 does not have replace-regexp-in-string, but XEmacs >= 21.5
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
85 ;; dumps it (it is defined in subr.el). Therefore, it is either defined
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
86 ;; regardless of what has been loaded already, or it won't be defined
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
87 ;; regardless of what is loaded.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
88 (if (not (fboundp 'replace-regexp-in-string))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
89 (defun replace-regexp-in-string (regexp rep string &optional
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
90 fixedcase literal subexp start)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
91 "Replace all matches for REGEXP with REP in STRING.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
92
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
93 Return a new string containing the replacements.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
94
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
95 Optional arguments FIXEDCASE, LITERAL and SUBEXP are like the
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
96 arguments with the same names of function `replace-match'. If START
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
97 is non-nil, start replacements at that index in STRING.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
98
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
99 REP is either a string used as the NEWTEXT arg of `replace-match' or a
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
100 function. If it is a function it is applied to each match to generate
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
101 the replacement passed to `replace-match'; the match-data at this
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
102 point are such that match 0 is the function's argument.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
103
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
104 To replace only the first match (if any), make REGEXP match up to \\'
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
105 and replace a sub-expression, e.g.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
106 (replace-regexp-in-string \"\\(foo\\).*\\'\" \"bar\" \" foo foo\" nil nil 1)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
107 => \" bar foo\"
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
108 "
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
109 (let ((l (length string))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
110 (start (or start 0))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
111 matches str mb me)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
112 (save-match-data
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
113 (while (and (< start l) (string-match regexp string start))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
114 (setq mb (match-beginning 0)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
115 me (match-end 0))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
116 ;; If we matched the empty string, make sure we advance by one char
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
117 (when (= me mb) (setq me (min l (1+ mb))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
118 ;; Generate a replacement for the matched substring.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
119 ;; Operate only on the substring to minimize string consing.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
120 ;; Set up match data for the substring for replacement;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
121 ;; presumably this is likely to be faster than munging the
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
122 ;; match data directly in Lisp.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
123 (string-match regexp (setq str (substring string mb me)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
124 (setq matches
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
125 (cons (replace-match (if (stringp rep)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
126 rep
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
127 (funcall rep (match-string 0 str)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
128 fixedcase literal str subexp)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
129 (cons (substring string start mb) ; unmatched prefix
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
130 matches)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
131 (setq start me))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
132 ;; Reconstruct a string from the pieces.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
133 (setq matches (cons (substring string start l) matches)) ; leftover
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
134 (apply #'concat (nreverse matches))))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
135
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
136
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
137 (defun easy-mmode-pretty-mode-name (mode &optional lighter)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
138 "Turn the symbol MODE into a string intended for the user.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
139 If provided LIGHTER will be used to help choose capitalization."
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
140 (let* ((case-fold-search t)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
141 (name (concat (replace-regexp-in-string
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
142 "-Minor" " minor"
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
143 (capitalize (replace-regexp-in-string
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
144 "-mode\\'" "" (symbol-name mode))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
145 " mode")))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
146 (if (not (stringp lighter)) name
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
147 (setq lighter
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
148 (replace-regexp-in-string "\\`\\s-+\\|\\-s+\\'" "" lighter))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
149 (replace-regexp-in-string lighter lighter name t t))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
150
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
151 ;; XEmacs change: add -on-hook, -off-hook, and macro parameter documentation.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
152 ;;;###no-autoload
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
153 (defalias 'easy-mmode-define-minor-mode 'define-minor-mode)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
154 ;;;###no-autoload
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
155 (defmacro define-minor-mode (mode doc &optional init-value lighter keymap &rest body)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
156 "Define a new minor mode MODE.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
157 This function defines the associated control variable MODE, keymap MODE-map,
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
158 toggle command MODE, and hook MODE-hook.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
159
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
160 DOC is the documentation for the mode toggle command.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
161 Optional INIT-VALUE is the initial value of the mode's variable.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
162 Optional LIGHTER is displayed in the modeline when the mode is on.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
163 Optional KEYMAP is the default (defvar) keymap bound to the mode keymap.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
164 If it is a list, it is passed to `easy-mmode-define-keymap'
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
165 in order to build a valid keymap. It's generally better to use
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
166 a separate MODE-map variable than to use this argument.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
167 The above three arguments can be skipped if keyword arguments are
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
168 used (see below).
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
169
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
170 BODY contains code that will be executed each time the mode is (de)activated.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
171 It will be executed after any toggling but before running the hooks.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
172 Before the actual body code, you can write
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
173 keyword arguments (alternating keywords and values).
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
174 These following keyword arguments are supported:
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
175 :group GROUP Custom group name to use in all generated `defcustom' forms.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
176 :global GLOBAL If non-nil specifies that the minor mode is not meant to be
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
177 buffer-local, so don't make the variable MODE buffer-local.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
178 By default, the mode is buffer-local.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
179 :init-value VAL Same as the INIT-VALUE argument.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
180 :lighter SPEC Same as the LIGHTER argument.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
181 :require SYM Same as in `defcustom'.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
182
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
183 For backwards compatibility, these hooks are run each time the mode is
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
184 \(de)activated. When the mode is toggled, MODE-hook is always run before the
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
185 other hook.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
186 MODE-hook: run if the mode is toggled.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
187 MODE-on-hook: run if the mode is activated.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
188 MODE-off-hook: run if the mode is deactivated.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
189
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
190 \(defmacro easy-mmode-define-minor-mode
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
191 (MODE DOC &optional INIT-VALUE LIGHTER KEYMAP &rest BODY)...\)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
192
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
193 For example, you could write
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
194 (define-minor-mode foo-mode \"If enabled, foo on you!\"
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
195 nil \"Foo \" foo-keymap
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
196 :require 'foo :global t :group 'inconvenience
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
197 ...BODY CODE...)"
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
198
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
199 ;; Allow skipping the first three args.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
200 (cond
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
201 ((keywordp init-value)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
202 (setq body (list* init-value lighter keymap body)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
203 init-value nil lighter nil keymap nil))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
204 ((keywordp lighter)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
205 (setq body (list* lighter keymap body) lighter nil keymap nil))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
206 ((keywordp keymap) (push keymap body) (setq keymap nil)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
207
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
208 (let* ((mode-name (symbol-name mode))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
209 (pretty-name (easy-mmode-pretty-mode-name mode lighter))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
210 (globalp nil)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
211 (group nil)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
212 (extra-args nil)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
213 (require t)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
214 (keymap-sym (if (and keymap (symbolp keymap)) keymap
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
215 (intern (concat mode-name "-map"))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
216 (hook (intern (concat mode-name "-hook")))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
217 (hook-on (intern (concat mode-name "-on-hook")))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
218 (hook-off (intern (concat mode-name "-off-hook"))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
219
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
220 ;; Check keys.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
221 (while (keywordp (car body))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
222 (case (pop body)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
223 (:init-value (setq init-value (pop body)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
224 (:lighter (setq lighter (pop body)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
225 (:global (setq globalp (pop body)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
226 (:extra-args (setq extra-args (pop body)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
227 (:group (setq group (nconc group (list :group (pop body)))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
228 (:require (setq require (pop body)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
229 (t (pop body))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
230
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
231 (unless group
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
232 ;; We might as well provide a best-guess default group.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
233 (setq group
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
234 `(:group ',(or (custom-current-group)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
235 (intern (replace-regexp-in-string
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
236 "-mode\\'" "" mode-name))))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
237 ;; Add default properties to LIGHTER.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
238 ;; #### FSF comments this out in 21.3.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
239 ; (unless (or (not (stringp lighter))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
240 ; (get-text-property 0 'local-map lighter)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
241 ; (get-text-property 0 'keymap lighter))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
242 ; (setq lighter
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
243 ; (propertize lighter
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
244 ; 'local-map modeline-minor-mode-map ; XEmacs change
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
245 ; 'help-echo "mouse-3: minor mode menu")))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
246
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
247 `(progn
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
248 ;; Define the variable to enable or disable the mode.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
249 ,(if (not globalp)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
250 `(progn
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
251 (defvar ,mode ,init-value ,(format "Non-nil if %s is enabled.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
252 Use the command `%s' to change this variable." pretty-name mode))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
253 (make-variable-buffer-local ',mode))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
254
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
255 (let ((curfile (or (and (boundp 'byte-compile-current-file)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
256 byte-compile-current-file)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
257 load-file-name)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
258 `(defcustom ,mode ,init-value
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
259 ,(format "Non-nil if %s is enabled.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
260 See the command `%s' for a description of this minor-mode.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
261 Setting this variable directly does not take effect;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
262 use either \\[customize] or the function `%s'."
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
263 pretty-name mode mode)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
264 :set (lambda (symbol value) (funcall symbol (or value 0)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
265 :initialize 'custom-initialize-default
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
266 ,@group
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
267 :type 'boolean
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
268 ,@(cond
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
269 ((not (and curfile require)) nil)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
270 ((not (eq require t)) `(:require ,require))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
271 (t `(:require
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
272 ',(intern (file-name-nondirectory
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
273 (file-name-sans-extension curfile)))))))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
274
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
275 ;; The actual function.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
276 (defun ,mode (&optional arg ,@extra-args)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
277 ,(or doc
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
278 (format (concat "Toggle %s on or off.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
279 Interactively, with no prefix argument, toggle the mode.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
280 With universal prefix ARG turn mode on.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
281 With zero or negative ARG turn mode off.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
282 \\{%s}") pretty-name keymap-sym))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
283 ;; Use `toggle' rather than (if ,mode 0 1) so that using
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
284 ;; repeat-command still does the toggling correctly.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
285 (interactive (list (or current-prefix-arg 'toggle)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
286 ;; XEmacs addition: save the old mode
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
287 (let ((old-mode ,mode))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
288 (setq ,mode
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
289 (cond
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
290 ((eq arg 'toggle) (not ,mode))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
291 (arg (or (listp arg);; XEmacs addition: C-u alone
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
292 (> (prefix-numeric-value arg) 0)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
293 (t
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
294 (if (null ,mode) t
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
295 (message
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
296 "Toggling %s off; better pass an explicit argument."
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
297 ',mode)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
298 nil))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
299 ,@body
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
300 ;; The on/off hooks are here for backward compatibility only.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
301 ;; The on/off hooks are here for backward compatibility only.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
302 ;; XEmacs change: check mode before running hooks
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
303 (and ,hook
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
304 (not (equal old-mode ,mode))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
305 (run-hooks ',hook))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
306 (and ,hook-on
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
307 ,mode
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
308 (run-hooks ',hook-on))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
309 (and ,hook-off
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
310 (not ,mode)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
311 (run-hooks ',hook-off)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
312 (if (interactive-p)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
313 (progn
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
314 ,(if globalp `(customize-mark-as-set ',mode))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
315 (message ,(format "%s %%sabled" pretty-name)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
316 (if ,mode "en" "dis"))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
317 (force-mode-line-update)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
318 ;; Return the new setting.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
319 ,mode)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
320
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
321 ;; Autoloading an easy-mmode-define-minor-mode autoloads
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
322 ;; everything up-to-here.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
323 ;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
324 ;; XEmacs change: XEmacs does not support :autoload-end. On the other
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
325 ;; hand, I don't see why we need to support it. An autoload cookie
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
326 ;; just before a (define-minor-mode foo) form will generate an autoload
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
327 ;; form for the file with name foo. But that's exactly right, since
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
328 ;; the defun created just above here has the name foo. There are no
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
329 ;; other top-level forms created above here by the macro, so we're done.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
330 ;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
331 ;;:autoload-end
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
332
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
333 ;; The toggle's hook.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
334 (defcustom ,hook nil
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
335 ,(format "Hook run at the end of function `%s'." mode-name)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
336 ,@group
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
337 :type 'hook)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
338
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
339 ;; XEmacs addition: declare the on and off hooks also
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
340 (defcustom ,hook-on nil
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
341 ,(format "Hook to run when entering %s." mode-name)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
342 :group ,(cadr group)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
343 :type 'hook)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
344
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
345 (defcustom ,hook-off nil
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
346 ,(format "Hook to run when exiting %s." mode-name)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
347 :group ,(cadr group)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
348 :type 'hook)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
349
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
350 ;; Define the minor-mode keymap.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
351 ,(unless (symbolp keymap) ;nil is also a symbol.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
352 `(defvar ,keymap-sym
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
353 (let ((m ,keymap))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
354 (cond ((keymapp m) m)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
355 ((listp m) (easy-mmode-define-keymap m))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
356 (t (error "Invalid keymap %S" ,keymap))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
357 ,(format "Keymap for `%s'." mode-name)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
358
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
359 (add-minor-mode ',mode ',lighter
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
360 ,(if keymap keymap-sym
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
361 `(if (boundp ',keymap-sym)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
362 (symbol-value ',keymap-sym)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
363 ;; XEmacs change: supply the AFTER and TOGGLE-FUN args
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
364 t ',mode)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
365
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
366 ;; If the mode is global, call the function according to the default.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
367 ,(if globalp
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
368 `(if (and load-file-name (not (equal ,init-value ,mode))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
369 ;; XEmacs addition:
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
370 (not purify-flag))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
371 (eval-after-load load-file-name '(,mode (if ,mode 1 -1))))))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
372
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
373 ;;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
374 ;;; make global minor mode
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
375 ;;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
376
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
377 ;;;###no-autoload
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
378 (defmacro easy-mmode-define-global-mode (global-mode mode turn-on
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
379 &rest keys)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
380 "Make GLOBAL-MODE out of the buffer-local minor MODE.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
381 TURN-ON is a function that will be called with no args in every buffer
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
382 and that should try to turn MODE on if applicable for that buffer.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
383 KEYS is a list of CL-style keyword arguments:
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
384 :group to specify the custom group."
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
385 (let* ((global-mode-name (symbol-name global-mode))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
386 (pretty-name (easy-mmode-pretty-mode-name mode))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
387 (pretty-global-name (easy-mmode-pretty-mode-name global-mode))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
388 (group nil)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
389 (extra-args nil)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
390 (buffers (intern (concat global-mode-name "-buffers")))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
391 (cmmh (intern (concat global-mode-name "-cmmh"))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
392
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
393 ;; Check keys.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
394 (while (keywordp (car keys))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
395 (case (pop keys)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
396 (:extra-args (setq extra-args (pop keys)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
397 (:group (setq group (nconc group (list :group (pop keys)))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
398 (t (setq keys (cdr keys)))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
399
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
400 (unless group
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
401 ;; We might as well provide a best-guess default group.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
402 (setq group
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
403 `(:group ',(or (custom-current-group)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
404 (intern (replace-regexp-in-string
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
405 "-mode\\'" "" (symbol-name mode)))))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
406
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
407 `(progn
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
408 ;; The actual global minor-mode
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
409 (define-minor-mode ,global-mode
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
410 ,(format "Toggle %s in every buffer.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
411 With prefix ARG, turn %s on if and only if ARG is positive.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
412 %s is actually not turned on in every buffer but only in those
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
413 in which `%s' turns it on."
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
414 pretty-name pretty-global-name pretty-name turn-on)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
415 :global t :extra-args ,extra-args ,@group
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
416
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
417 ;; Setup hook to handle future mode changes and new buffers.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
418 (if ,global-mode
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
419 ;; XEmacs: find-file-hooks not find-file-hook
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
420 (progn
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
421 (add-hook 'find-file-hooks ',buffers)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
422 (add-hook 'change-major-mode-hook ',cmmh))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
423 (remove-hook 'find-file-hooks ',buffers)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
424 (remove-hook 'change-major-mode-hook ',cmmh))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
425
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
426 ;; Go through existing buffers.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
427 (dolist (buf (buffer-list))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
428 (with-current-buffer buf
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
429 (if ,global-mode (,turn-on) (when ,mode (,mode -1))))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
430
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
431 ;; TODO: XEmacs does not support :autoload-end
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
432 ;; Autoloading easy-mmode-define-global-mode
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
433 ;; autoloads everything up-to-here.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
434 :autoload-end
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
435
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
436 ;; List of buffers left to process.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
437 (defvar ,buffers nil)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
438
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
439 ;; The function that calls TURN-ON in each buffer.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
440 (defun ,buffers ()
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
441 (remove-hook 'post-command-hook ',buffers)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
442 (while ,buffers
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
443 (let ((buf (pop ,buffers)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
444 (when (buffer-live-p buf)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
445 (with-current-buffer buf (,turn-on))))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
446 (put ',buffers 'definition-name ',global-mode)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
447
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
448 ;; The function that catches kill-all-local-variables.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
449 (defun ,cmmh ()
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
450 (add-to-list ',buffers (current-buffer))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
451 (add-hook 'post-command-hook ',buffers))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
452 (put ',cmmh 'definition-name ',global-mode))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
453
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
454 ;;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
455 ;;; easy-mmode-defmap
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
456 ;;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
457
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
458 (if (fboundp 'set-keymap-parents)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
459 (defalias 'easy-mmode-set-keymap-parents 'set-keymap-parents)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
460 (defun easy-mmode-set-keymap-parents (m parents)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
461 (set-keymap-parent
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
462 m
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
463 (cond
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
464 ((not (consp parents)) parents)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
465 ((not (cdr parents)) (car parents))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
466 (t (let ((m (copy-keymap (pop parents))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
467 (easy-mmode-set-keymap-parents m parents)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
468 m))))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
469
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
470 ;;;###no-autoload
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
471 (defun easy-mmode-define-keymap (bs &optional name m args)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
472 "Return a keymap built from bindings BS.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
473 BS must be a list of (KEY . BINDING) where
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
474 KEY and BINDINGS are suitable for `define-key'.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
475 Optional NAME is passed to `make-sparse-keymap'.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
476 Optional map M can be used to modify an existing map.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
477 ARGS is a list of additional keyword arguments."
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
478 (let (inherit dense ;suppress
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
479 )
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
480 (while args
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
481 (let ((key (pop args))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
482 (val (pop args)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
483 (case key
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
484 (:name (setq name val))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
485 (:dense (setq dense val))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
486 (:inherit (setq inherit val))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
487 (:group)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
488 ;;((eq key :suppress) (setq suppress val))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
489 (t (message "Unknown argument %s in defmap" key)))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
490 (unless (keymapp m)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
491 (setq bs (append m bs))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
492 (setq m (if dense (make-keymap name) (make-sparse-keymap name))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
493 (dolist (b bs)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
494 (let ((keys (car b))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
495 (binding (cdr b)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
496 (dolist (key (if (consp keys) keys (list keys)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
497 (cond
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
498 ((symbolp key)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
499 (substitute-key-definition key binding m global-map))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
500 ((null binding)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
501 (unless (keymapp (lookup-key m key)) (define-key m key binding)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
502 ((let ((o (lookup-key m key)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
503 (or (null o) (numberp o) (eq o 'undefined)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
504 (define-key m key binding))))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
505 (cond
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
506 ((keymapp inherit) (set-keymap-parent m inherit))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
507 ((consp inherit) (easy-mmode-set-keymap-parents m inherit)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
508 m))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
509
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
510 ;;;###no-autoload
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
511 (defmacro easy-mmode-defmap (m bs doc &rest args)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
512 `(defconst ,m
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
513 (easy-mmode-define-keymap ,bs nil (if (boundp ',m) ,m) ,(cons 'list args))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
514 ,doc))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
515
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
516
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
517 ;;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
518 ;;; easy-mmode-defsyntax
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
519 ;;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
520
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
521 (defun easy-mmode-define-syntax (css args)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
522 (let ((st (make-syntax-table (plist-get args :copy)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
523 (parent (plist-get args :inherit)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
524 (dolist (cs css)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
525 (let ((char (car cs))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
526 (syntax (cdr cs)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
527 (if (sequencep char)
4783
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 2548
diff changeset
528 (mapc (lambda (c) (modify-syntax-entry c syntax st)) char)
2548
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
529 (modify-syntax-entry char syntax st))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
530 ;; XEmacs change: we do not have set-char-table-parent
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
531 (if parent (derived-mode-merge-syntax-tables
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
532 (if (symbolp parent) (symbol-value parent) parent) st))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
533 st))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
534
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
535 ;;;###no-autoload
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
536 (defmacro easy-mmode-defsyntax (st css doc &rest args)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
537 "Define variable ST as a syntax-table.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
538 CSS contains a list of syntax specifications of the form (CHAR . SYNTAX)."
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
539 `(progn
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
540 (autoload 'easy-mmode-define-syntax "easy-mmode")
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
541 (defconst ,st (easy-mmode-define-syntax ,css ,(cons 'list args)) ,doc)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
542
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
543
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
544
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
545 ;;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
546 ;;; easy-mmode-define-navigation
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
547 ;;;
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
548
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
549 ;; XEmacs change: autoload
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
550 ;;;###no-autoload
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
551 (defmacro easy-mmode-define-navigation (base re &optional name endfun)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
552 "Define BASE-next and BASE-prev to navigate in the buffer.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
553 RE determines the places the commands should move point to.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
554 NAME should describe the entities matched by RE. It is used to build
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
555 the docstrings of the two functions.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
556 BASE-next also tries to make sure that the whole entry is visible by
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
557 searching for its end (by calling ENDFUN if provided or by looking for
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
558 the next entry) and recentering if necessary.
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
559 ENDFUN should return the end position (with or without moving point)."
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
560 (let* ((base-name (symbol-name base))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
561 (prev-sym (intern (concat base-name "-prev")))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
562 (next-sym (intern (concat base-name "-next"))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
563 (unless name (setq name (symbol-name base-name)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
564 `(progn
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
565 (add-to-list 'debug-ignored-errors
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
566 ,(concat "^No \\(previous\\|next\\) " (regexp-quote name)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
567 (defun ,next-sym (&optional count)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
568 ,(format "Go to the next COUNT'th %s." name)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
569 (interactive)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
570 (unless count (setq count 1))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
571 (if (< count 0) (,prev-sym (- count))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
572 (if (looking-at ,re) (incf count))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
573 (if (not (re-search-forward ,re nil t count))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
574 (if (looking-at ,re)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
575 (goto-char (or ,(if endfun `(,endfun)) (point-max)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
576 (error ,(format "No next %s" name)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
577 (goto-char (match-beginning 0))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
578 (when (and (eq (current-buffer) (window-buffer (selected-window)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
579 (interactive-p))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
580 (let ((endpt (or (save-excursion
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
581 ,(if endfun `(,endfun)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
582 `(re-search-forward ,re nil t 2)))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
583 (point-max))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
584 ;; XEmacs change: versions < 21.5.16 have a
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
585 ;; pos-visible-in-window-p that takes only 2 parameters
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
586 (unless
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
587 (if (eq (function-max-args #'pos-visible-in-window-p) 2)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
588 (pos-visible-in-window-p endpt nil)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
589 (pos-visible-in-window-p endpt nil t))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
590 (recenter '(0))))))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
591 (defun ,prev-sym (&optional count)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
592 ,(format "Go to the previous COUNT'th %s" (or name base-name))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
593 (interactive)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
594 (unless count (setq count 1))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
595 (if (< count 0) (,next-sym (- count))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
596 (unless (re-search-backward ,re nil t count)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
597 (error ,(format "No previous %s" name))))))))
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
598
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
599 (provide 'easy-mmode)
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
600
c4c8a36043be [xemacs-hg @ 2005-02-03 07:11:19 by ben]
ben
parents:
diff changeset
601 ;;; easy-mmode.el ends here