Previous: , Up: Customization Basics   [Contents][Index]

4.2 Customizing Menus

You can customize any of the SXEmacs Pull-down-Menus. You can create your own menu, delete an existing one, enable a menu or disable a menu. For more information on the default menus available to you, See Pull-down Menus.

Some of the functions which are available to you for customization are:

  1. add-menu-item: (menu-name item-name function enabled-p &optional before)

    This function will add a menu item to a menu, creating the menu first if necessary. If the named item already exists, the menu will remain unchanged. For example, if you add the following example to your init.el file or evaluate it (see Customization Basics),

    (add-menu-item '("Edit") "Replace String" replace-string t "Clear")

    a sub-menu Replace String will be created under Edit menu before the sub-menu Clear. The Edit menu will now look like:

    Undo                    C-x u
    Cut                     cut
    Copy                    copy
    Paste                   paste
    Replace String
    Start Macro Recording   C-x(
    End Macro Recording     C-x)
    Execute Last Macro      C-xe

    Replace String will now execute the function replace-string. Select this menu item. SXEmacs will prompt you for a string name to be replaced. Type a string and hit RET. Now type a new string to replace the old string and hit RET. All occurrences of the old string will be replaced by the new string. In this example,

    Edit’ is the menu-name which identifies the menu into which the new menu item should be inserted.

    Replace String’ is the item-name which names the menu item to be added.

    replace-string’ is the function i.e. the command to be invoked when the menu item "Replace String" is selected.

    t’ is the enabled-p parameter which controls whether the menu item is selectable or not. This parameter can be either t (selectable), nil (not selectable), or a form to evaluate. This form is evaluated just before the menu is displayed, and the menu item will be selectable if the form returns non-nil.

    Clear’ is the &optional before parameter which is the name of the menu before which the new menu or sub-menu should be added. The &optional string means that this parameter is optional. You do not need to specify this parameter. If you do not specify this parameter in the example above, the Replace String menu item will be added at the end of the list of sub-menus in the Edit menu i.e. after Execute Last Macro.

    If you wish to add a new menu to the menubar, try:

    (add-menu-item nil "Bot" 'end-of-buffer t)

    This will create a new menu Bot on the menu bar. Selecting this menu will take you to the end of the buffer. Using nil for the parameter menu-name will create a new menu. Your menu-bar will now look like:

    File Edit Options Buffers Bot                         Help

    The following example will illustrate how you can add sub-menus to the submenus themselves:

    (add-menu-item '("File" "Management") "Copy File" 'copy-file t)
    (add-menu-item '("File" "Management") "Delete File" 'delete-file t)
    (add-menu-item '("File" "Management") "Rename File" 'rename-file t)

    This will create a sub-menu Management under the File menu. When you select the submenu Management, it will contain three submenus: Copy File, Delete File and Rename File.

  2. delete-menu-item: (menu-path) This function will remove the menu item defined by menu-name from the menu hierarchy. Look at the following examples and the comments just above them which specify what the examples do.
    ;; deletes the "Replace String" menu item created earlier
    (delete-menu-item '("Edit" "Replace String"))
    ;; deletes the "Bot" menu created earlier
    (delete-menu-item '("Bot"))
    ;; deletes the sub-menu "Copy File" created earlier
    (delete-menu-item '("File" "File Management" "Copy File"))
    ;; deletes the sub-menu "Delete File" created earlier
    (delete-menu-item '("File" "Management" "Delete File"))
    ;; deletes the sub-menu "Rename File" created earlier
    (delete-menu-item '("File" "Management" "Rename File"))
  3. disable-menu-item: (menu-name) Disables the specified menu item. The following example
    (disable-menu-item '("File" "Management" "Copy File"))

    will make the Copy File item unselectable. This menu-item would still be there but it will appear faded which would mean that it cannot be selected.

  4. enable-menu-item: (menu-name) Enables the specified previously disabled menu item.
    (enable-menu-item '("File" "Management" "Copy File"))

    This will enable the sub-menu Copy File, which was disabled by the earlier command.

  5. relabel-menu-item: (menu-name new-name) Change the string of the menu item specified by menu-name to new-name.
    (relabel-menu-item '("File" "Open...") "Open File")

    This example will rename the Open... menu item from the File menu to Open File.

Previous: , Up: Customization Basics   [Contents][Index]