unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Decebal <CLDWesterhof@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Extra info in modeline (tip and questions)
Date: Wed, 15 Apr 2009 04:06:28 -0700 (PDT)	[thread overview]
Message-ID: <f0e47524-4ddd-4b13-935b-a474e52bfcdb@r33g2000yqn.googlegroups.com> (raw)
In-Reply-To: 533fdd2a-8d26-47ce-9413-1bd2300ee2d1@s20g2000yqh.googlegroups.com

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
        )
      )


  parent reply	other threads:[~2009-04-15 11:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-14 14:03 Extra info in modeline (tip and questions) Decebal
2009-04-14 15:54 ` Nikolaj Schumacher
     [not found] ` <mailman.5329.1239724470.31690.help-gnu-emacs@gnu.org>
2009-04-15  5:53   ` Decebal
2009-04-15 13:14     ` Nikolaj Schumacher
     [not found]     ` <mailman.5377.1239801271.31690.help-gnu-emacs@gnu.org>
2009-04-28  7:55       ` Decebal
2009-04-28 10:27         ` Decebal
2009-04-28  8:04       ` Decebal
2009-04-28  8:23         ` Decebal
2009-04-15 11:06 ` Decebal [this message]
2009-04-15 13:23   ` Nikolaj Schumacher
     [not found]   ` <mailman.5379.1239801830.31690.help-gnu-emacs@gnu.org>
2009-04-15 16:13     ` Decebal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f0e47524-4ddd-4b13-935b-a474e52bfcdb@r33g2000yqn.googlegroups.com \
    --to=cldwesterhof@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).