changeset 83017:4c6128c0d7e2

Merged in changes from CVS HEAD Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-32 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-57
author Karoly Lorentey <lorentey@elte.hu>
date Mon, 12 Jan 2004 16:36:35 +0000
parents 1d7467694692 (current diff) a93ed629b104 (diff)
children 1465425fe2d3
files src/xmenu.c
diffstat 13 files changed, 343 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/etc/NEWS	Mon Jan 12 00:45:42 2004 +0000
+++ b/etc/NEWS	Mon Jan 12 16:36:35 2004 +0000
@@ -481,6 +481,13 @@
 On the other hand, the size of the thumb does not represent the actual
 amount of text shown any more (only a crude approximation of it).
 
+---
+** The pop up menus for Lucid now stay up if you do a fast click and can
+be navigated with the arrow keys (like Gtk+ and W32).
+
+---
+** Dialogs for Lucid/Athena and Lesstif/Motif pops down when pressing ESC.
+
 +++
 ** The file selection dialog for Gtk+, W32 and Motif/Lesstif can be
 disabled by customizing the variable `use-file-dialog'.
@@ -946,6 +953,12 @@
 This can be controlled through the variables `diary-header-line-flag'
 and `diary-header-line-format'.
 
++++
+** The procedure for activating appointment reminders has changed: use
+the new function `appt-activate'. The new variable
+`appt-display-format' controls how reminders are displayed, replacing
+appt-issue-message, appt-visible, and appt-msg-window.
+
 ** VC Changes
 
 *** The key C-x C-q no longer checks files in or out, it only changes
--- a/lisp/calendar/appt.el	Mon Jan 12 00:45:42 2004 +0000
+++ b/lisp/calendar/appt.el	Mon Jan 12 16:36:35 2004 +0000
@@ -79,6 +79,18 @@
 
 
 ;;;###autoload
+(defcustom appt-issue-message t
+  "*Non-nil means check for appointments in the diary buffer.
+To be detected, the diary entry must have the format described in the
+documentation of the function `appt-check'."
+  :type 'boolean
+  :group 'appt)
+
+(make-obsolete-variable 'appt-issue-message
+                        "use the function `appt-activate', and the \
+variable `appt-display-format' instead." "21.4")
+
+;;;###autoload
 (defcustom appt-message-warning-time 12
   "*Time in minutes before an appointment that the warning begins."
   :type 'integer
--- a/lispref/ChangeLog	Mon Jan 12 00:45:42 2004 +0000
+++ b/lispref/ChangeLog	Mon Jan 12 16:36:35 2004 +0000
@@ -1,3 +1,16 @@
+2004-01-11  Luc Teirlinck  <teirllm@auburn.edu>
+
+	* searching.texi: Various small changes in addition to the
+	following.
+	(Regexp Example): Adapt to new value of `sentence-end'.
+	(Regexp Functions): The PAREN argument to `regexp-opt' can be
+	`words'.
+	(Search and Replace): Add usage note for `perform-replace'.
+	(Entire Match Data): Mention INTEGERS and REUSE arguments to
+	`match-data'.
+	(Standard Regexps): Update for new values of `paragraph-start'
+	and `sentence-end'.
+
 2004-01-07  Luc Teirlinck  <teirllm@auburn.edu>
 
 	* files.texi (Saving Buffers): Clarify descriptions of
--- a/lispref/searching.texi	Mon Jan 12 00:45:42 2004 +0000
+++ b/lispref/searching.texi	Mon Jan 12 16:36:35 2004 +0000
@@ -90,7 +90,8 @@
 search is repeated that many times (each time starting at the end of the
 previous time's match).  If these successive searches succeed, the
 function succeeds, moving point and returning its new value.  Otherwise
-the search fails, leaving point where it started.
+the search fails, with results depending on the value of
+@var{noerror}, as described above.
 @end deffn
 
 @deffn Command search-backward string &optional limit noerror repeat
@@ -143,7 +144,7 @@
 an error if the search fails.  If @var{noerror} is @code{t}, then it
 returns @code{nil} instead of signaling an error.  If @var{noerror} is
 neither @code{nil} nor @code{t}, it moves point to @var{limit} (or the
-end of the buffer) and returns @code{nil}.
+end of the accessible portion of the buffer) and returns @code{nil}.
 
 If @var{repeat} is non-@code{nil}, then the search is repeated that many
 times.  Point is positioned at the end of the last match.
@@ -168,8 +169,8 @@
 
 @menu
 * Syntax of Regexps::       Rules for writing regular expressions.
+* Regexp Example::          Illustrates regular expression syntax.
 * Regexp Functions::        Functions for operating on regular expressions.
-* Regexp Example::          Illustrates regular expression syntax.
 @end menu
 
 @node Syntax of Regexps
@@ -293,10 +294,10 @@
 
 You can also include character ranges in a character alternative, by
 writing the starting and ending characters with a @samp{-} between them.
-Thus, @samp{[a-z]} matches any lower-case @acronym{ASCII} letter.  Ranges may be
-intermixed freely with individual characters, as in @samp{[a-z$%.]},
-which matches any lower case @acronym{ASCII} letter or @samp{$}, @samp{%} or
-period.
+Thus, @samp{[a-z]} matches any lower-case @acronym{ASCII} letter.
+Ranges may be intermixed freely with individual characters, as in
+@samp{[a-z$%.]}, which matches any lower case @acronym{ASCII} letter
+or @samp{$}, @samp{%} or period.
 
 Note that the usual regexp special characters are not special inside a
 character alternative.  A completely different set of characters is
@@ -358,10 +359,11 @@
 
 @item @samp{^}
 @cindex beginning of line in regexp
-is a special character that matches the empty string, but only at the
-beginning of a line in the text being matched.  Otherwise it fails to
-match anything.  Thus, @samp{^foo} matches a @samp{foo} that occurs at
-the beginning of a line.
+When matching a buffer, @samp{^} matches the empty string, but only at the
+beginning of a line in the text being matched (or the beginning of the
+accessible portion of the buffer).  Otherwise it fails to match
+anything.  Thus, @samp{^foo} matches a @samp{foo} that occurs at the
+beginning of a line.
 
 When matching a string instead of a buffer, @samp{^} matches at the
 beginning of the string or after a newline character.
@@ -372,8 +374,9 @@
 @item @samp{$}
 @cindex @samp{$} in regexp
 @cindex end of line in regexp
-is similar to @samp{^} but matches only at the end of a line.  Thus,
-@samp{x+$} matches a string of one @samp{x} or more at the end of a line.
+is similar to @samp{^} but matches only at the end of a line (or the
+end of the accessible portion of the buffer).  Thus, @samp{x+$}
+matches a string of one @samp{x} or more at the end of a line.
 
 When matching a string instead of a buffer, @samp{$} matches at the end
 of the string or before a newline character.
@@ -542,7 +545,7 @@
 operators), but it does not get a number, so you cannot refer back to
 its value with @samp{\@var{digit}}.
 
-Shy groups are particulary useful for mechanically-constructed regular
+Shy groups are particularly useful for mechanically-constructed regular
 expressions because they can be added automatically without altering the
 numbering of any ordinary, non-shy groups.
 
@@ -567,6 +570,10 @@
 half, which may be anything, but the @samp{\1} that follows must match
 the same exact text.
 
+If a @samp{\( @dots{} \)} construct matches more than once (which can
+happen, for instance, if it is followed by @samp{*}), only the last
+match is recorded.
+
 If a particular grouping construct in the regular expression was never
 matched---for instance, if it appears inside of an alternative that
 wasn't used, or inside of a repetition that repeated zero times---then
@@ -611,7 +618,9 @@
 
   The following regular expression constructs match the empty string---that is,
 they don't use up any characters---but whether they match depends on the
-context.
+context.  For all, the beginning and end of the accessible portion of
+the buffer are treated as if they were the actual beginning and end of
+the buffer.
 
 @table @samp
 @item \`
@@ -636,25 +645,25 @@
 @samp{foo} as a separate word.  @samp{\bballs?\b} matches
 @samp{ball} or @samp{balls} as a separate word.@refill
 
-@samp{\b} matches at the beginning or end of the buffer
+@samp{\b} matches at the beginning or end of the buffer (or string)
 regardless of what text appears next to it.
 
 @item \B
 @cindex @samp{\B} in regexp
 matches the empty string, but @emph{not} at the beginning or
-end of a word.
+end of a word, nor at the beginning or end of the buffer (or string).
 
 @item \<
 @cindex @samp{\<} in regexp
 matches the empty string, but only at the beginning of a word.
-@samp{\<} matches at the beginning of the buffer only if a
+@samp{\<} matches at the beginning of the buffer (or string) only if a
 word-constituent character follows.
 
 @item \>
 @cindex @samp{\>} in regexp
 matches the empty string, but only at the end of a word.  @samp{\>}
-matches at the end of the buffer only if the contents end with a
-word-constituent character.
+matches at the end of the buffer (or string) only if the contents end
+with a word-constituent character.
 @end table
 
 @kindex invalid-regexp
@@ -668,9 +677,11 @@
 @comment  node-name,  next,  previous,  up
 @subsection Complex Regexp Example
 
-  Here is a complicated regexp, used by Emacs to recognize the end of a
-sentence together with any whitespace that follows.  It is the value of
-the variable @code{sentence-end}.
+  Here is a complicated regexp which was formerly used by Emacs to
+recognize the end of a sentence together with any whitespace that
+follows.  It was used as the variable @code{sentence-end}.  (Its value
+nowadays contains alternatives for @samp{.}, @samp{?} and @samp{!} in
+other character sets.)
 
   First, we show the regexp as a string in Lisp syntax to distinguish
 spaces from tab characters.  The string constant begins and ends with a
@@ -679,17 +690,16 @@
 tab and @samp{\n} for a newline.
 
 @example
-"[.?!][]\"')@}]*\\($\\| $\\|\t\\|  \\)[ \t\n]*"
+"[.?!][]\"')@}]*\\($\\| $\\|\t\\|@ @ \\)[ \t\n]*"
 @end example
 
 @noindent
-In contrast, if you evaluate the variable @code{sentence-end}, you
-will see the following:
+In contrast, if you evaluate this string, you will see the following:
 
 @example
 @group
-sentence-end
-     @result{} "[.?!][]\"')@}]*\\($\\| $\\|  \\|  \\)[
+"[.?!][]\"')@}]*\\($\\| $\\|\t\\|@ @ \\)[ \t\n]*"
+     @result{} "[.?!][]\"')@}]*\\($\\| $\\|  \\|@ @ \\)[
 ]*"
 @end group
 @end example
@@ -704,7 +714,10 @@
 @item [.?!]
 The first part of the pattern is a character alternative that matches
 any one of three characters: period, question mark, and exclamation
-mark.  The match must begin with one of these three characters.
+mark.  The match must begin with one of these three characters.  (This
+is the one point where the new value of @code{sentence-end} differs
+from the old.  The new value also lists sentence ending
+non-@acronym{ASCII} characters.)
 
 @item []\"')@}]*
 The second part of the pattern matches any closing braces and quotation
@@ -764,13 +777,14 @@
 
 @defun regexp-opt strings &optional paren
 This function returns an efficient regular expression that will match
-any of the strings @var{strings}.  This is useful when you need to make
-matching or searching as fast as possible---for example, for Font Lock
-mode.
+any of the strings in the list @var{strings}.  This is useful when you
+need to make matching or searching as fast as possible---for example,
+for Font Lock mode.
 
 If the optional argument @var{paren} is non-@code{nil}, then the
 returned regular expression is always enclosed by at least one
-parentheses-grouping construct.
+parentheses-grouping construct.  If @var{paren} is @code{words}, then
+that construct is additionally surrounded by @samp{\<} and @samp{\>}.
 
 This simplified definition of @code{regexp-opt} produces a
 regular expression which is equivalent to the actual value
@@ -788,7 +802,8 @@
 
 @defun regexp-opt-depth regexp
 This function returns the total number of grouping constructs
-(parenthesized expressions) in @var{regexp}.
+(parenthesized expressions) in @var{regexp}.  (This does not include
+shy groups.)
 @end defun
 
 @node Regexp Search
@@ -830,7 +845,7 @@
 @code{re-search-forward} does nothing and returns @code{nil}.  If
 @var{noerror} is neither @code{nil} nor @code{t}, then
 @code{re-search-forward} moves point to @var{limit} (or the end of the
-buffer) and returns @code{nil}.
+accessible portion of the buffer) and returns @code{nil}.
 
 In the following example, point is initially before the @samp{T}.
 Evaluating the search call moves point to the end of that line (between
@@ -866,9 +881,10 @@
 beginning is as close as possible to the starting point.  If
 @code{re-search-backward} were a perfect mirror image, it would find the
 match whose end is as close as possible.  However, in fact it finds the
-match whose beginning is as close as possible.  The reason for this is that
-matching a regular expression at a given spot always works from
-beginning to end, and starts at a specified beginning position.
+match whose beginning is as close as possible (and yet ends before the
+starting point).  The reason for this is that matching a regular
+expression at a given spot always works from beginning to end, and
+starts at a specified beginning position.
 
 A true mirror-image of @code{re-search-forward} would require a special
 feature for matching regular expressions from end to beginning.  It's
@@ -1069,7 +1085,8 @@
 commands.  It searches for occurrences of @var{from-string} in the
 text between positions @var{start} and @var{end} and replaces some or
 all of them.  If @var{start} is @code{nil} (or omitted), point is used
-instead, and the buffer's end is used for @var{end}.
+instead, and the end of the buffer's accessible portion is used for
+@var{end}.
 
 If @var{query-flag} is @code{nil}, it replaces all
 occurrences; otherwise, it asks the user what to do about each one.
@@ -1090,7 +1107,7 @@
 
 If @var{repeat-count} is non-@code{nil}, it should be an integer.  Then
 it specifies how many times to use each of the strings in the
-@var{replacements} list before advancing cyclicly to the next one.
+@var{replacements} list before advancing cyclically to the next one.
 
 If @var{from-string} contains upper-case letters, then
 @code{perform-replace} binds @code{case-fold-search} to @code{nil}, and
@@ -1099,6 +1116,22 @@
 Normally, the keymap @code{query-replace-map} defines the possible user
 responses for queries.  The argument @var{map}, if non-@code{nil}, is a
 keymap to use instead of @code{query-replace-map}.
+
+@strong{Usage note:} Do not use this function in your own programs
+unless you want to do something very similar to what
+@code{query-replace} does, including setting the mark and possibly
+querying the user.  For most purposes a simple loop like, for
+instance:
+
+@example
+(while (re-search-forward "foo[ \t]+bar" nil t)
+  (replace-match "foobar"))
+@end example
+
+@noindent
+is preferable.  It runs faster and avoids side effects, such as
+setting the mark.  @xref{Replacing Match,, Replacing the Text that
+Matched}, for a description of @code{replace-match}.
 @end defun
 
 @defvar query-replace-map
@@ -1205,9 +1238,11 @@
 @var{replacement}.
 
 If you did the last search in a buffer, you should specify @code{nil}
-for @var{string}.  Then @code{replace-match} does the replacement by
-editing the buffer; it leaves point at the end of the replacement text,
-and returns @code{t}.
+for @var{string} and make sure that the current buffer when you call
+@code{replace-match} is the one in which you did the searching or
+matching.  Then @code{replace-match} does the replacement by editing
+the buffer; it leaves point at the end of the replacement text, and
+returns @code{t}.
 
 If you did the search in a string, pass the same string as @var{string}.
 Then @code{replace-match} does the replacement by constructing and
@@ -1239,6 +1274,7 @@
 @samp{\@var{n}}, where @var{n} is a digit, stands for the text that
 matched the @var{n}th subexpression in the original regexp.
 Subexpressions are those expressions grouped inside @samp{\(@dots{}\)}.
+If the @var{n}th subexpression never matched, an empty string is substituted.
 
 @item @samp{\\}
 @cindex @samp{\} in replacement
@@ -1396,7 +1432,7 @@
   The functions @code{match-data} and @code{set-match-data} read or
 write the entire match data, all at once.
 
-@defun match-data
+@defun match-data &optional integers reuse
 This function returns a newly constructed list containing all the
 information on what text the last search matched.  Element zero is the
 position of the beginning of the match for the whole expression; element
@@ -1420,8 +1456,20 @@
 corresponds to @code{(match-end @var{n})}.
 
 All the elements are markers or @code{nil} if matching was done on a
-buffer, and all are integers or @code{nil} if matching was done on a
-string with @code{string-match}.
+buffer and all are integers or @code{nil} if matching was done on a
+string with @code{string-match}.   If @var{integers} is
+non-@code{nil}, then all elements are integers or @code{nil}, even if
+matching was done on a buffer.  Also, @code{match-beginning} and
+@code{match-end} always return integers or @code{nil}.
+
+If @var{reuse} is non-@code{nil}, it should be a list.  In that case,
+@code{match-data} stores the match data in @var{reuse}.  That is,
+@var{reuse} is destructively modified.  @var{reuse} does not need to
+have the right length.  If it is not long enough to contain the match
+data, it is extended.  If it is too long, the length of @var{reuse}
+stays the same, but the elements that were not used are set to
+@code{nil}.  The purpose of this feature is to avoid producing too
+much garbage, that would later have to be collected.
 
 As always, there must be no possibility of intervening searches between
 the call to a search function and the call to @code{match-data} that is
@@ -1474,7 +1522,8 @@
 
 @defmac save-match-data body@dots{}
 This macro executes @var{body}, saving and restoring the match
-data around it.
+data around it.  The return value is the value of the last form in
+@var{body}.
 @end defmac
 
   You could use @code{set-match-data} together with @code{match-data} to
@@ -1544,10 +1593,11 @@
 searching functions used in Lisp code.
 
 @defopt case-replace
-This variable determines whether the replacement functions should
-preserve case.  If the variable is @code{nil}, that means to use the
-replacement text verbatim.  A non-@code{nil} value means to convert the
-case of the replacement text according to the text being replaced.
+This variable determines whether the higher level replacement
+functions should preserve case.  If the variable is @code{nil}, that
+means to use the replacement text verbatim.  A non-@code{nil} value
+means to convert the case of the replacement text according to the
+text being replaced.
 
 This variable is used by passing it as an argument to the function
 @code{replace-match}.  @xref{Replacing Match}.
@@ -1600,22 +1650,23 @@
 @defvar paragraph-start
 This is the regular expression for recognizing the beginning of a line
 that starts @emph{or} separates paragraphs.  The default value is
-@w{@code{"[@ \t\n\f]"}}, which matches a line starting with a space, tab,
-newline, or form feed (after its left margin).
+@w{@code{"\f\\|[ \t]*$"}}, which matches a line containing only
+whitespace or starting with a form feed (after its left margin).
 @end defvar
 
 @defvar sentence-end
 This is the regular expression describing the end of a sentence.  (All
-paragraph boundaries also end sentences, regardless.)  The default value
-is:
+paragraph boundaries also end sentences, regardless.)  The (slightly
+simplified) default value is:
 
 @example
-"[.?!][]\"')@}]*\\($\\| $\\|\t\\| \\)[ \t\n]*"
+"[.?!][]\"')@}]*\\($\\| $\\|\t\\|@ @ \\)[ \t\n]*"
 @end example
 
-This means a period, question mark or exclamation mark, followed
-optionally by a closing parenthetical character, followed by tabs,
-spaces or new lines.
+This means a period, question mark or exclamation mark (the actual
+default value also lists their alternatives in other character sets),
+followed optionally by a closing parenthetical character, followed by
+tabs, spaces or new lines.
 
 For a detailed explanation of this regular expression, see @ref{Regexp
 Example}.
--- a/lwlib/ChangeLog	Mon Jan 12 00:45:42 2004 +0000
+++ b/lwlib/ChangeLog	Mon Jan 12 16:36:35 2004 +0000
@@ -1,3 +1,31 @@
+2004-01-12  Jan Dj,Ad(Brv  <jan.h.d@swipnet.se>
+
+	* xlwmenuP.h (_XlwMenu_part): Added top_depth.
+
+	* xlwmenu.h: Removed declaration of pop_up_menu
+
+	* xlwmenu.c (Start): Get correct time if time in event is CurrentTime.
+	(find_first_selectable, find_next_selectable)
+	(find_prev_selectable): Add parameter skip_no_call_data to skip
+	over items with no call data (popup menu titles).
+	(Down, Up): Compare old_depth to top_depth instead of 2.
+	Pass True to find_*_selectable:s new parameter if this is a popup menu.
+	(Left, Right): Compare old_depth to top_depth instead of 2.
+	Pass 0 to find_*_selectable:s new parameter.
+	(pop_up_menu): Set top_depth to 1 for pop up menus and 2 for
+	menu bar menus, to enable keyboard traversal of popups.
+
+	* lwlib-Xm.c (dialog_key_cb): New function.
+	(make_dialog): Add event handlers to dialog_key_cb for key press
+	so we can pop down on ESC.
+
+	* lwlib-Xlw.c (xlw_popup_menu): Replace call to pop_up_menu with
+	XtCallActionProc ("start").  Use a full XEvent since "start" copies it.
+
+	* lwlib-Xaw.c (make_dialog): Add override so dialog pops down
+	on ESC.
+	(wm_delete_window): If widget isn't a shell, use the parent.
+
 2003-05-22  Dave Love  <fx@gnu.org>
 
 	* xlwmenu.c: Include lisp.h, not ../src/lisp.h.
--- a/lwlib/lwlib-Xaw.c	Mon Jan 12 00:45:42 2004 +0000
+++ b/lwlib/lwlib-Xaw.c	Mon Jan 12 16:36:35 2004 +0000
@@ -277,6 +277,9 @@
 
 static char overrideTrans[] =
 	"<Message>WM_PROTOCOLS: lwlib_delete_dialog()";
+/* Dialogs pop down on any key press */
+static char dialogOverride[] =
+       "<KeyPress>:	lwlib_delete_dialog()";
 static void wm_delete_window();
 static XtActionsRec xaw_actions [] = {
   {"lwlib_delete_dialog", wm_delete_window}
@@ -333,6 +336,8 @@
 
   ac = 0;
   dialog = XtCreateManagedWidget (name, dialogWidgetClass, shell, av, ac);
+  override = XtParseTranslationTable (dialogOverride);
+  XtOverrideTranslations (dialog, override);
 
   bc = 0;
   button = 0;
@@ -511,8 +516,8 @@
 }
 
 static void
-wm_delete_window (shell, closure, call_data)
-     Widget shell;
+wm_delete_window (w, closure, call_data)
+     Widget w;
      XtPointer closure;
      XtPointer call_data;
 {
@@ -520,7 +525,13 @@
   Cardinal nkids;
   int i;
   Widget *kids = 0;
-  Widget widget;
+  Widget widget, shell;
+
+  if (XtIsSubclass (w, dialogWidgetClass))
+    shell = XtParent (w);
+  else
+    shell = w;
+
   if (! XtIsSubclass (shell, shellWidgetClass))
     abort ();
   XtVaGetValues (shell, XtNnumChildren, &nkids, NULL);
--- a/lwlib/lwlib-Xlw.c	Mon Jan 12 00:45:42 2004 +0000
+++ b/lwlib/lwlib-Xlw.c	Mon Jan 12 16:36:35 2004 +0000
@@ -180,6 +180,7 @@
   XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
   XtAddCallback (widget, XtNhighlightCallback, highlight_hook,
 		 (XtPointer)instance);
+
   return popup_shell;
 }
 
@@ -251,7 +252,6 @@
      Widget widget;
      XEvent *event;
 {
-  XButtonPressedEvent dummy;
   XlwMenuWidget mw;
 
   if (!XtIsShell (widget))
@@ -260,21 +260,24 @@
   mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
 
   if (event)
-    pop_up_menu (mw, (XButtonPressedEvent*) event);
+    XtCallActionProc ((Widget) mw, "start", event, NULL, 0);
   else
     {
-      dummy.type = ButtonPress;
-      dummy.serial = 0;
-      dummy.send_event = 0;
-      dummy.display = XtDisplay (widget);
-      dummy.window = XtWindow (XtParent (widget));
-      dummy.time = CurrentTime;
-      dummy.button = 0;
-      XQueryPointer (dummy.display, dummy.window, &dummy.root,
-		     &dummy.subwindow, &dummy.x_root, &dummy.y_root,
-		     &dummy.x, &dummy.y, &dummy.state);
+      XEvent dummy;
+      XButtonPressedEvent *bd = &dummy.xbutton;
 
-      pop_up_menu (mw, &dummy);
+      bd->type = ButtonPress;
+      bd->serial = 0;
+      bd->send_event = 0;
+      bd->display = XtDisplay (widget);
+      bd->window = XtWindow (XtParent (widget));
+      bd->time = CurrentTime;
+      bd->button = 0;
+      XQueryPointer (bd->display, bd->window, &bd->root,
+		     &bd->subwindow, &bd->x_root, &bd->y_root,
+		     &bd->x, &bd->y, &bd->state);
+
+      XtCallActionProc ((Widget) mw, "start", &dummy, NULL, 0);
     }
 }
 
--- a/lwlib/lwlib-Xm.c	Mon Jan 12 00:45:42 2004 +0000
+++ b/lwlib/lwlib-Xm.c	Mon Jan 12 16:36:35 2004 +0000
@@ -1035,6 +1035,33 @@
 
 /* creation functions */
 
+/* Called for key press in dialogs.  Used to pop down dialog on ESC.  */
+static void
+dialog_key_cb (widget, closure, event, continue_to_dispatch)
+     Widget widget;
+     XtPointer closure;
+     XEvent *event;
+     Boolean *continue_to_dispatch;
+{
+  KeySym sym = 0;
+  Modifiers modif_ret;
+  
+  XtTranslateKeycode (event->xkey.display, event->xkey.keycode, 0,
+                      &modif_ret, &sym);
+                      
+  if (sym == osfXK_Cancel)
+    {
+      Widget w = *((Widget *) closure);
+
+      while (w && ! XtIsShell (w))
+        w = XtParent (w);
+
+      if (XtIsShell (w)) XtPopdown (w);
+    }
+
+  *continue_to_dispatch = TRUE;
+}
+
 /* dialogs */
 static Widget
 make_dialog (name, parent, pop_up_p, shell_title, icon_name, text_input_slot,
@@ -1123,6 +1150,8 @@
       XtSetArg(al[ac], XmNmarginWidth, 10); ac++;
       XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
       children [n_children] = XmCreatePushButton (row, button_name, al, ac);
+      XtAddEventHandler (children [n_children],
+                         KeyPressMask, False, dialog_key_cb, result);
 
       if (i == 0)
 	{
@@ -1149,6 +1178,9 @@
       XtSetArg(al[ac], XmNmarginWidth, 10); ac++;
       XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
       children [n_children] = XmCreatePushButton (row, button_name, al, ac);
+      XtAddEventHandler (children [n_children],
+                         KeyPressMask, False, dialog_key_cb, result);
+
       if (! button) button = children [n_children];
       n_children++;
     }
@@ -1491,6 +1523,7 @@
 
   XtAddCallback (widget, XmNpopdownCallback, xm_nosel_callback,
 		 (XtPointer) instance);
+
   return widget;
 }
 
--- a/lwlib/xlwmenu.c	Mon Jan 12 00:45:42 2004 +0000
+++ b/lwlib/xlwmenu.c	Mon Jan 12 16:36:35 2004 +0000
@@ -197,6 +197,8 @@
 static void Key();
 static void Nothing();
 static int separator_height __P ((enum menu_separator));
+static void pop_up_menu __P ((XlwMenuWidget, XButtonPressedEvent *));
+
 
 static XtActionsRec
 xlwMenuActionsList [] =
@@ -2004,6 +2006,13 @@
   if (!mw->menu.popped_up)
     {
       menu_post_event = *ev;
+      /* If event is set to CurrentTime, get the last known time stamp.
+         This is for calculating if (popup) menus should stay up after
+         a fast click.  */
+      if (menu_post_event.xbutton.time == CurrentTime)
+        menu_post_event.xbutton.time
+          = XtLastTimestampProcessed (XtDisplay (w));
+
       pop_up_menu (mw, (XButtonPressedEvent*) ev);
     }
   else
@@ -2044,15 +2053,17 @@
 {
 }
 
-widget_value *
-find_first_selectable (mw, item)
+static widget_value *
+find_first_selectable (mw, item, skip_no_call_data)
      XlwMenuWidget mw;
      widget_value *item;
+     int skip_no_call_data;
 {
   widget_value *current = item;
   enum menu_separator separator;
 
-  while (lw_separator_p (current->name, &separator, 0) || !current->enabled)
+  while (lw_separator_p (current->name, &separator, 0) || !current->enabled
+         || (skip_no_call_data && !current->call_data))
     if (current->next)
       current=current->next;
     else
@@ -2061,8 +2072,8 @@
   return current;
 }
 
-widget_value *
-find_next_selectable (mw, item)
+static widget_value *
+find_next_selectable (mw, item, skip_no_call_data)
      XlwMenuWidget mw;
      widget_value *item;
 {
@@ -2070,7 +2081,8 @@
   enum menu_separator separator;
 
   while (current->next && (current=current->next) &&
-	 (lw_separator_p (current->name, &separator, 0) || !current->enabled))
+	 (lw_separator_p (current->name, &separator, 0) || !current->enabled
+          || (skip_no_call_data && !current->call_data)))
     ;
 
   if (current == item)
@@ -2079,7 +2091,9 @@
 	return current;
       current = mw->menu.old_stack [mw->menu.old_depth - 2]->contents;
 
-      while (lw_separator_p (current->name, &separator, 0) || !current->enabled)
+      while (lw_separator_p (current->name, &separator, 0)
+             || !current->enabled
+             || (skip_no_call_data && !current->call_data))
 	{
 	  if (current->next)
 	    current=current->next;
@@ -2093,15 +2107,16 @@
   return current;
 }
 
-widget_value *
-find_prev_selectable (mw, item)
+static widget_value *
+find_prev_selectable (mw, item, skip_no_call_data)
      XlwMenuWidget mw;
      widget_value *item;
 {
   widget_value *current = item;
   widget_value *prev = item;
 
-  while ((current=find_next_selectable (mw, current)) != item)
+  while ((current=find_next_selectable (mw, current, skip_no_call_data))
+         != item)
     {
       if (prev == current)
 	break;
@@ -2120,15 +2135,23 @@
 {
   XlwMenuWidget mw = (XlwMenuWidget) w;
   widget_value* selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
+  int popup_menu_p = mw->menu.top_depth == 1;
 
   /* Inside top-level menu-bar?  */
-  if (mw->menu.old_depth == 2)
+  if (mw->menu.old_depth == mw->menu.top_depth)
     /* When <down> in the menu-bar is pressed, display the corresponding
-       sub-menu and select the first selectable menu item there.  */
-    set_new_state (mw, find_first_selectable (mw, selected_item->contents), mw->menu.old_depth);
+       sub-menu and select the first selectable menu item there.
+       If this is a popup menu, skip items with zero call data (title of
+       the popup).  */
+    set_new_state (mw,
+                   find_first_selectable (mw,
+                                          selected_item->contents,
+                                          popup_menu_p),
+                   mw->menu.old_depth);
   else
     /* Highlight next possible (enabled and not separator) menu item.  */
-    set_new_state (mw, find_next_selectable (mw, selected_item), mw->menu.old_depth - 1);
+    set_new_state (mw, find_next_selectable (mw, selected_item, popup_menu_p),
+                   mw->menu.old_depth - 1);
 
   remap_menubar (mw);
 }
@@ -2142,27 +2165,39 @@
 {
   XlwMenuWidget mw = (XlwMenuWidget) w;
   widget_value* selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
+  int popup_menu_p = mw->menu.top_depth == 1;
 
   /* Inside top-level menu-bar?  */
-  if (mw->menu.old_depth == 2)
+  if (mw->menu.old_depth == mw->menu.top_depth)
     {
       /* FIXME: this is tricky.  <up> in the menu-bar should select the
 	 last selectable item in the list.  So we select the first
 	 selectable one and find the previous selectable item.  Is there
 	 a better way?  */
-      set_new_state (mw, find_first_selectable (mw, selected_item->contents), mw->menu.old_depth);
+      /* If this is a popup menu, skip items with zero call data (title of
+         the popup).  */
+      set_new_state (mw,
+                     find_first_selectable (mw,
+                                            selected_item->contents,
+                                            popup_menu_p),
+                     mw->menu.old_depth);
       remap_menubar (mw);
       selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
-      set_new_state (mw, find_prev_selectable (mw, selected_item), mw->menu.old_depth - 1);
+      set_new_state (mw,
+                     find_prev_selectable (mw,
+                                           selected_item,
+                                           popup_menu_p),
+                     mw->menu.old_depth - 1);
     }
   else
     /* Highlight previous (enabled and not separator) menu item.  */
-    set_new_state (mw, find_prev_selectable (mw, selected_item), mw->menu.old_depth - 1);
+    set_new_state (mw, find_prev_selectable (mw, selected_item, popup_menu_p),
+                   mw->menu.old_depth - 1);
 
   remap_menubar (mw);
 }
 
-static void
+void
 Left (w, ev, params, num_params)
      Widget w;
      XEvent *ev;
@@ -2173,31 +2208,36 @@
   widget_value* selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
 
   /* Inside top-level menu-bar?  */
-  if (mw->menu.old_depth == 2)
+  if (mw->menu.old_depth == mw->menu.top_depth)
     /* When <left> in the menu-bar is pressed, display the previous item on
        the menu-bar. If the current item is the first one, highlight the
        last item in the menubar (probably Help).  */
-    set_new_state (mw, find_prev_selectable (mw, selected_item), mw->menu.old_depth - 1);
+    set_new_state (mw, find_prev_selectable (mw, selected_item, 0),
+                   mw->menu.old_depth - 1);
   else if (mw->menu.old_depth == 1
 	   && selected_item->contents)     /* Is this menu item expandable?  */
     {
       set_new_state (mw, selected_item->contents, mw->menu.old_depth);
       remap_menubar (mw);
       selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
-      if (!selected_item->enabled && find_first_selectable (mw, selected_item))
-	set_new_state (mw, find_first_selectable (mw, selected_item), mw->menu.old_depth - 1);
+      if (!selected_item->enabled && find_first_selectable (mw,
+                                                            selected_item,
+                                                            0))
+	set_new_state (mw, find_first_selectable (mw, selected_item, 0),
+                       mw->menu.old_depth - 1);
     }
 
   else
     {
       pop_new_stack_if_no_contents (mw);
-      set_new_state (mw, mw->menu.old_stack [mw->menu.old_depth - 2], mw->menu.old_depth - 2);
+      set_new_state (mw, mw->menu.old_stack [mw->menu.old_depth - 2],
+                     mw->menu.old_depth - 2);
     }
 
   remap_menubar (mw);
 }
 
-static void
+void
 Right (w, ev, params, num_params)
      Widget w;
      XEvent *ev;
@@ -2208,23 +2248,28 @@
   widget_value* selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
 
   /* Inside top-level menu-bar?  */
-  if (mw->menu.old_depth == 2)
+  if (mw->menu.old_depth == mw->menu.top_depth)
     /* When <right> in the menu-bar is pressed, display the next item on
        the menu-bar. If the current item is the last one, highlight the
        first item (probably File).  */
-    set_new_state (mw, find_next_selectable (mw, selected_item), mw->menu.old_depth - 1);
+    set_new_state (mw, find_next_selectable (mw, selected_item, 0),
+                   mw->menu.old_depth - 1);
   else if (selected_item->contents)     /* Is this menu item expandable?  */
     {
       set_new_state (mw, selected_item->contents, mw->menu.old_depth);
       remap_menubar (mw);
       selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
-      if (!selected_item->enabled && find_first_selectable (mw, selected_item))
-	set_new_state (mw, find_first_selectable (mw, selected_item), mw->menu.old_depth - 1);
+      if (!selected_item->enabled && find_first_selectable (mw,
+                                                            selected_item,
+                                                            0))
+	set_new_state (mw, find_first_selectable (mw, selected_item, 0),
+                       mw->menu.old_depth - 1);
     }
   else
     {
       pop_new_stack_if_no_contents (mw);
-      set_new_state (mw, mw->menu.old_stack [mw->menu.old_depth - 2], mw->menu.old_depth - 2);
+      set_new_state (mw, mw->menu.old_stack [mw->menu.old_depth - 2],
+                     mw->menu.old_depth - 2);
     }
 
   remap_menubar (mw);
@@ -2305,7 +2350,7 @@
 
 
 /* Special code to pop-up a menu */
-void
+static void
 pop_up_menu (mw, event)
      XlwMenuWidget mw;
      XButtonPressedEvent* event;
@@ -2349,6 +2394,7 @@
       display_menu (mw, 0, False, NULL, NULL, NULL, NULL, NULL);
       mw->menu.windows [0].x = x + borderwidth;
       mw->menu.windows [0].y = y + borderwidth;
+      mw->menu.top_depth = 1;  /* Popup menus don't have a bar so top is 1  */
     }
   else
     {
@@ -2359,6 +2405,7 @@
       /* notes the absolute position of the menubar window */
       mw->menu.windows [0].x = ev->xmotion.x_root - ev->xmotion.x;
       mw->menu.windows [0].y = ev->xmotion.y_root - ev->xmotion.y;
+      mw->menu.top_depth = 2;
     }
 
 #ifdef emacs
--- a/lwlib/xlwmenu.h	Mon Jan 12 00:45:42 2004 +0000
+++ b/lwlib/xlwmenu.h	Mon Jan 12 16:36:35 2004 +0000
@@ -53,9 +53,6 @@
 
 extern WidgetClass xlwMenuWidgetClass;
 
-void
-pop_up_menu __P ((XlwMenuWidget, XButtonPressedEvent*));
-
 #endif /* _XlwMenu_h */
 
 /* arch-tag: 0c019735-d61b-4080-be85-4fdd6e50ae07
--- a/lwlib/xlwmenuP.h	Mon Jan 12 00:45:42 2004 +0000
+++ b/lwlib/xlwmenuP.h	Mon Jan 12 16:36:35 2004 +0000
@@ -47,6 +47,7 @@
   unsigned free_bottom_shadow_color_p : 1;
 
   /* State of the XlwMenu */
+  int                   top_depth;
   int			old_depth;
   widget_value**	old_stack;
   int			old_stack_length;
--- a/src/ChangeLog	Mon Jan 12 00:45:42 2004 +0000
+++ b/src/ChangeLog	Mon Jan 12 16:36:35 2004 +0000
@@ -1,3 +1,13 @@
+2004-01-12  Jan Dj,Ad(Brv  <jan.h.d@swipnet.se>
+
+	* xmenu.c (popup_get_selection): Check new parameter down_on_keypress
+	if a key press should pop down.  Only pop down if a key is pressed
+	outside the menu/dialog.
+	(create_and_show_popup_menu): Pass 0 for down_on_keypress to
+	popup_get_selection.
+	(create_and_show_dialog): Pass 1 for down_on_keypress to
+	popup_get_selection.
+
 2004-01-11  Jan Dj,Ad(Brv  <jan.h.d@swipnet.se>
 
 	* alloc.c (allocate_vectorlike): Surround calls to mallopt with
--- a/src/xmenu.c	Mon Jan 12 00:45:42 2004 +0000
+++ b/src/xmenu.c	Mon Jan 12 16:36:35 2004 +0000
@@ -1121,17 +1121,19 @@
    and x-popup-dialog; it is not used for the menu bar.
 
    If DO_TIMERS is nonzero, run timers.
+   If DOWN_ON_KEYPRESS is nonzero, pop down if a key is pressed.
 
    NOTE: All calls to popup_get_selection should be protected
    with BLOCK_INPUT, UNBLOCK_INPUT wrappers.  */
 
 #ifdef USE_X_TOOLKIT
 static void
-popup_get_selection (initial_event, dpyinfo, id, do_timers)
+popup_get_selection (initial_event, dpyinfo, id, do_timers, down_on_keypress)
      XEvent *initial_event;
      struct x_display_info *dpyinfo;
      LWLIB_ID id;
      int do_timers;
+     int down_on_keypress;
 {
   XEvent event;
 
@@ -1167,15 +1169,20 @@
           event.xbutton.state = 0;
 #endif
         }
-      /* If the user presses a key, deactivate the menu.
+      /* If the user presses a key that doesn't go to the menu,
+         deactivate the menu.
          The user is likely to do that if we get wedged.
-         This is mostly for Lucid, Motif pops down the menu on ESC.  */
+         All toolkits now pop down menus on ESC.
+         For dialogs however, the focus may not be on the dialog, so
+         in that case, we pop down. */
       else if (event.type == KeyPress
+               && down_on_keypress
                && dpyinfo->display == event.xbutton.display)
         {
           KeySym keysym = XLookupKeysym (&event.xkey, 0);
-          if (!IsModifierKey (keysym))
-            popup_activated_flag = 0;
+          if (!IsModifierKey (keysym)
+              && x_any_window_to_frame (dpyinfo, event.xany.window) != NULL)
+	    popup_activated_flag = 0;
         }
 
       x_dispatch_event (&event, event.xany.display);
@@ -2448,7 +2455,7 @@
   popup_activated_flag = 1;
 
   /* Process events that apply to the menu.  */
-  popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), menu_id, 0);
+  popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), menu_id, 0, 0);
 
   /* fp turned off the following statement and wrote a comment
      that it is unnecessary--that the menu has already disappeared.
@@ -2842,7 +2849,8 @@
                            Fcons (make_number (dialog_id >> (fact)),
                                   make_number (dialog_id & ~(-1 << (fact)))));
 
-    popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f), dialog_id, 1);
+    popup_get_selection ((XEvent *) 0, FRAME_X_DISPLAY_INFO (f),
+                         dialog_id, 1, 1);
 
     unbind_to (count, Qnil);
   }