[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Extra info in modeline (tip and questions)
From: |
Decebal |
Subject: |
Re: Extra info in modeline (tip and questions) |
Date: |
Wed, 15 Apr 2009 04:06:28 -0700 (PDT) |
User-agent: |
G2/1.0 |
On 14 apr, 16:03, Decebal <CLDWester...@gmail.com> wrote:
I was not happy with get-mode-line-field. Especially with the
(catch 'break
I understand that this is the default way to handle a break out of a
loop, but I found it ugly, and I expect it is also expensive. So I
rewrote it in such a way that the catch is not neccesary anymore. I
made it also a little bit more general. I do not need it at the
moment, but I made a function to fetch the struct with the right type.
So I changed:
> (defun get-mode-line-field(type)
> (let ((i 0)
> (field (format "*%s*" type))
> (total (length mode-line-array))
> )
> (catch 'break
> (while (< i total)
> (if (equal type (mode-line-struct-type (aref mode-line-
> array i)))
> (progn (setq field
> (format "%s: %s "
> (mode-line-struct-display (aref
> mode-line-array i))
> (funcall (mode-line-struct-
> function (aref mode-line-array i)))
> )
> )
> (throw 'break nil)
> )
> )
> (incf i)
> )
> )
> field
> )
> )
into:
(defun get-mode-line-struct(type)
(let ((i 0)
(this-struct nil)
(not-ready t)
(total (length mode-line-array))
)
(while (and not-ready (< i total))
(if (equal type (mode-line-struct-type (aref mode-line-array
i)))
(setq this-struct (aref mode-line-array i)
not-ready nil
)
(incf i)
)
)
this-struct
)
)
(defun get-mode-line-field(type)
(let ((field (format "*%s*" type))
(this-struct (get-mode-line-struct type))
)
(if this-struct
(setq field
(format "%s: %s "
(mode-line-struct-display this-struct)
(funcall (mode-line-struct-function this-
struct))
)
)
)
field
)
)
Re: Extra info in modeline (tip and questions),
Decebal <=