diff -ru less-381-orig/less.nro less-381/less.nro
--- less-381-orig/less.nro	2003-01-18 06:15:38.000000000 +0100
+++ less-381/less.nro	2003-12-13 18:26:13.000000000 +0100
@@ -1266,6 +1266,10 @@
 Usually used at the end of the string, but may appear anywhere.
 .IP "%x"
 Replaced by the name of the next input file in the list.
+.IP "%["
+Causes the remaining part not to be considered for the total length of the
+prompt. This is useful for setting the xterm title. See ?X below. (This is
+analogous to \e[ in bash's $PS1, but lacks the corresponding \e].)
 .PP
 If any item is unknown (for example, the file size if input
 is a pipe), a question mark is printed instead.
@@ -1316,6 +1320,8 @@
 .IP "?x"
 True if there is a next input file
 (that is, if the current input file is not the last one).
+.IP "?X"
+True if the terminal has a title bar. ($TERM matches xterm* or screen*.)
 .PP
 Any characters other than the special ones
 (question mark, colon, period, percent, and backslash)
@@ -1366,6 +1372,12 @@
 .sp
 ?f%f\ .?m(file\ %i\ of\ %m)\ .?ltlines\ %lt-%lb?L/%L.\ .
 	byte\ %bB?s/%s.\ ?e(END)\ :?pB%pB\e%..%t
+.sp
+.fi
+To put the filename in the xterm title bar, append the following to a prompt:
+.nf
+.sp
+	?X%[\e033]0;less\ ?f%f:stdin.\e007.
 .fi
 .PP
 The prompt expansion features are also used for another purpose:
diff -ru less-381-orig/prompt.c less-381/prompt.c
--- less-381-orig/prompt.c	2003-01-18 05:55:17.000000000 +0100
+++ less-381/prompt.c	2003-12-13 18:14:19.000000000 +0100
@@ -60,6 +60,7 @@
 
 static char message[PROMPT_SIZE];
 static char *mp;
+static char *mp_nonprint;	/* marker for end of printable part */
 
 /*
  * Initialize the prompt prototype strings.
@@ -183,6 +184,7 @@
 	int where;
 {
 	POSITION len;
+	char *term;
 
 	switch (c)
 	{
@@ -230,6 +232,10 @@
 			return (0);
 #endif
 		return (next_ifile(curr_ifile) != NULL_IFILE);
+	case 'X':	/* Return true for xterm* and screen* */
+		if(!(term = lgetenv("TERM")))
+			return 0;
+		return !strncmp(term, "xterm", 5) || !strncmp(term, "screen", 6);
 	}
 	return (0);
 }
@@ -365,6 +371,12 @@
 		else
 			ap_quest();
 		break;
+	case '[':	/* The following part is non-printing */
+		mp_nonprint = mp;
+		break;
+	/* TODO: implement a %] pattern
+	 * at the moment only one %[ pattern is recognized, extending to the end of
+	 * the string */
 	}
 }
 
@@ -467,6 +479,7 @@
 	int where;
 
 	mp = message;
+	mp_nonprint = NULL;
 
 	if (*proto == '\0')
 		return ("");
@@ -519,6 +532,9 @@
 
 	if (mp == message)
 		return (NULL);
+	if (mp_nonprint)	/* stop marker is set */
+		/* consider printable part for width calculation */
+		mp = mp_nonprint;
 	if (maxwidth > 0 && mp >= message + maxwidth)
 	{
 		/*
