Thanks, Lei, your code works. And I has extended it to a lisp codesnnipet, which is exactly what I want.

I post it here, in case others need it.

Notice: There is an enhancement here, which is replacing setq with local variables.
I tried to do this, but has failed, due to my poor lisp.
Since this is a minor issue for me, so I keep lazy here. ^-^

;; -------------------------- separator --------------------------
(setq frame-title-format
      '(:eval (concat "Ask 5 why, Denny! -- " (buffer-name) " -- "
                      (progn
                        (if buffer-file-name
                            (setq buffer_name_str buffer-file-name)
                          (setq buffer_name_str ""))
                        (if (< (length buffer_name_str) 50)
                            buffer_name_str
                          (concat (substring buffer_name_str 0 20) "..."
                                  (substring buffer_name_str
                                             (- (length buffer_name_str) 30)
                                             (length buffer_name_str))
                           ))))))

;; -------------------------- separator --------------------------

Regards,
Denny


On Sat, Jul 31, 2010 at 3:30 PM, Wang Lei <f3d27b@gmail.com> wrote:
On 7/31/10, filebat Mark <filebat.mark@gmail.com> wrote:
> Hi Lennart
>
> I tried  (setq frame-title-format "%f - Emacs"), it's cool.
>
> However, the full filename of "%f" is usually too long.
> Can I truncate the string with fixed length?
>
> Regards,
> Denny
You can try this.
(setq frame-title-format '(:eval (concat (if (< 10 (length buffer-file-name))
                                            (concat (substring buffer-file-name 0 6) "...")
                                          buffer-file-name)
                                        "- Emacs")))

I assume 10 is the max length of filename than you want to.


>
> On 7/28/10, Lennart Borgman <lennart.borgman@gmail.com> wrote:
>>
>> On Wed, Jul 28, 2010 at 3:14 PM, Kevin Rodgers
>> <kevin.d.rodgers@gmail.com> wrote:
>> >
>> > Tim Visher wrote:
>> >>
>> >> Hi everyone,
>> >>
>> >> I'm wondering if there's a simple way to postfix ' emacs' to all frame
>> >> titles without resorting to [elisp from the web][1].  Couldn't find
>> >> anything in Chapter 25 but I didn't search much harder than that.
>> >>
>> >> [1]: http://www.emacswiki.org/emacs/FrameTitle
>> >
>> > No, you need to use Emacs Lisp: that is the "format" of customizations
>> > in ~/.emacs (M-x customize notwithstanding).
>> >
>> > Here's what I use:
>> >
>> > (setq frame-title-format
>> >      '("" invocation-name "-" emacs-version "@" system-name ":"
>> >        (buffer-file-name "%f" "%b")))
>>
>>
>>
>> In EmacsW32 I use
>>
>>   (setq frame-title-format "%b - Emacs")
>>
>> This is probably what people on ms windows expect. Is that what people
>> on other GUI systems expect as well?
>>
>>
>
>
> --
> Thanks & Regards
>
> Denny Zhang
>


--
Regards,
Lei



--
Thanks & Regards

Denny Zhang